From 33596f9638758d5dcdf794351bcf551ce9d0139f Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 6 Apr 2021 22:27:23 +0000 Subject: [PATCH] Added hopper_drop_run_trigger_all option Moved dialable_leads function to functions.php Added 'dialable_count' option to list_info Non-Agent API function git-svn-id: svn://192.168.202.10@3420 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/bin/AST_VDhopper.pl | 47 +- agc_2-X/trunk/docs/NON-AGENT_API.txt | 4 +- .../AST_campaign_status_list_report.php | 1564 +++++----- .../www/vicidial/AST_dial_log_report.php | 1420 ++++----- .../vicidial/AST_dialer_inventory_report.php | 2118 ++++++------- .../www/vicidial/AST_hangup_cause_report.php | 1860 ++++++------ .../www/vicidial/AST_inbound_forecasting.php | 2686 ++++++++--------- .../vicidial/AST_source_vlc_status_report.php | 1326 ++++---- .../vicidial/AST_user_group_hourly_detail.php | 1432 ++++----- .../AST_user_group_hourly_detail_v2.php | 1486 ++++----- agc_2-X/trunk/www/vicidial/admin.php | 1005 +----- agc_2-X/trunk/www/vicidial/admin_mobile.php | 957 ------ .../trunk/www/vicidial/count_functions.inc | 368 --- agc_2-X/trunk/www/vicidial/functions.php | 967 ++++++ .../trunk/www/vicidial/help_documentation.txt | 4 +- agc_2-X/trunk/www/vicidial/non_agent_api.php | 50 +- 16 files changed, 8039 insertions(+), 9255 deletions(-) diff --git a/agc_2-X/trunk/bin/AST_VDhopper.pl b/agc_2-X/trunk/bin/AST_VDhopper.pl index 8f46d2d8..1b5bbb16 100644 --- a/agc_2-X/trunk/bin/AST_VDhopper.pl +++ b/agc_2-X/trunk/bin/AST_VDhopper.pl @@ -22,7 +22,7 @@ # - S = Standard hopper load # - D = Campaign Drop-Run # -# Copyright (C) 2020 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2021 Matt Florell LICENSE: AGPLv2 # # CHANGELOG # 50810-1613 - Added database server variable definitions lookup @@ -100,10 +100,11 @@ # 201111-1359 - Added support for hopper_drop_run_trigger # 201122-1039 - Added support for daily call count limits # 201220-1032 - Changes for shared agent campaigns +# 210405-1008 - Added hopper_drop_run_trigger=A option # # constants -$build = '201220-1032'; +$build = '210405-1008'; $DB=0; # Debug flag, set to 0 for no debug messages. Can be overriden with CLI --debug flag $US='__'; $MT[0]=''; @@ -2658,10 +2659,40 @@ foreach(@campaign_id) $hopperPRIORITY='0'; ##### Load overrides if Hopper Drop-Run is triggered ##### - if ($hopper_drop_run_trigger[$i] =~ /Y/) + if ($hopper_drop_run_trigger[$i] =~ /Y|A/) { + if ($hopper_drop_run_trigger[$i] =~ /A/) + { + $ALL_drop_statuses="'DROP','PDROP','XDROP'"; + $stmtA = "SELECT status FROM vicidial_statuses where status LIKE \"%DROP%\" or status_name LIKE \"%DROP%\";"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsA=$sthA->rows; + $rec_count=0; + while ($sthArowsA > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $ALL_drop_statuses .= ",'$aryA[0]'"; + $rec_count++; + } + $sthA->finish(); + $stmtA = "SELECT status FROM vicidial_campaign_statuses where status LIKE \"%DROP%\" or status_name LIKE \"%DROP%\";"; + $sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr; + $sthA->execute or die "executing: $stmtA ", $dbhA->errstr; + $sthArowsA=$sthA->rows; + $rec_count=0; + while ($sthArowsA > $rec_count) + { + @aryA = $sthA->fetchrow_array; + $ALL_drop_statuses .= ",'$aryA[0]'"; + $rec_count++; + } + $sthA->finish(); + } + else + {$ALL_drop_statuses="'DROP'";} $cslrSQL=''; - $STATUSsql[$i]="'DROP'"; + $STATUSsql[$i] = $ALL_drop_statuses; $list_order_mix[$i]='DISABLED'; $lead_order[$i]='DOWN LAST CALL TIME'; $hopper_level[$i]='20000'; @@ -2672,8 +2703,8 @@ foreach(@campaign_id) $affected_rows = $dbhA->do($stmtA); if ($DBX) {print "CAMPAIGN Hopper Drop-Run RESET: $affected_rows|$stmtA|\n";} - if ($DB) {print "Campaign Drop-Run triggered for $campaign_id[$i] |$STATUSsql[$i]|$list_order_mix[$i]|$affected_rows|\n";} - $hopper_begin_output .= "Campaign Drop-Run triggered for $campaign_id[$i] |$STATUSsql[$i]|$list_order_mix[$i]|$affected_rows| \n"; + if ($DB) {print "Campaign Drop-Run triggered for $campaign_id[$i]($hopper_drop_run_trigger[$i]) |$STATUSsql[$i]|$list_order_mix[$i]|$affected_rows|\n";} + $hopper_begin_output .= "Campaign Drop-Run triggered for $campaign_id[$i]($hopper_drop_run_trigger[$i]) |$STATUSsql[$i]|$list_order_mix[$i]|$affected_rows| \n"; } ##### Get count of leads that are dialable ##### @@ -3371,13 +3402,13 @@ foreach(@campaign_id) $insert_end_output .= " DNC lead skipped: $DNCskip \n"; $insert_end_output .= " Daily call count limit lead skipped: $DCCLskip \n"; if ($DB) {print "$insert_end_output";} - $insert_end_outputSQL = ",adapt_output='$insert_end_output'"; + $insert_end_outputSQL = ",adapt_output=\"$insert_end_output\""; } } } } # update debug output - $stmtA = "UPDATE vicidial_campaign_stats_debug SET entry_time='$now_date',debug_output='$hopper_begin_output'$insert_end_outputSQL where campaign_id='$campaign_id[$i]' and server_ip='HOPPER';"; + $stmtA = "UPDATE vicidial_campaign_stats_debug SET entry_time='$now_date',debug_output=\"$hopper_begin_output\"$insert_end_outputSQL where campaign_id='$campaign_id[$i]' and server_ip='HOPPER';"; $affected_rows = $dbhA->do($stmtA); $i++; diff --git a/agc_2-X/trunk/docs/NON-AGENT_API.txt b/agc_2-X/trunk/docs/NON-AGENT_API.txt index 11c6e5d1..42241cb1 100644 --- a/agc_2-X/trunk/docs/NON-AGENT_API.txt +++ b/agc_2-X/trunk/docs/NON-AGENT_API.txt @@ -1,4 +1,4 @@ -NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2021-04-02 +NON-AGENT API DOCUMENT Started: 2008-07-24 Updated: 2021-04-06 This document describes the functions of an API(Application Programming Interface) for all functions NOT directly relating to the VICIDIAL Agent screen. @@ -185,6 +185,7 @@ Changes: 210330-1633 - Added ability to use custom_fields_copy on update_list on a deleted list_id 210401-1058 - Added 'custom_fields_update' option for update_list function 210402-1102 - Added 'custom_fields_delete' option for update_list function +210406-1047 - Added 'dialable_count' option to list_info function API Functions use the 'function' variable @@ -1843,6 +1844,7 @@ source - description of what originated the API call (maximum 20 characters) SETTINGS FIELDS- (optional) leads_counts - Y or N, will include the counts of all leads and NEW status leads in the response, default is 'N' +dialable_count - Y or N, will use the list's campaign settings to provide a count of how many are dialable right now, default is 'N' 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 diff --git a/agc_2-X/trunk/www/vicidial/AST_campaign_status_list_report.php b/agc_2-X/trunk/www/vicidial/AST_campaign_status_list_report.php index 1ce2cb84..b4788835 100644 --- a/agc_2-X/trunk/www/vicidial/AST_campaign_status_list_report.php +++ b/agc_2-X/trunk/www/vicidial/AST_campaign_status_list_report.php @@ -1,782 +1,782 @@ - LICENSE: AGPLv2 -# -# CHANGES -# -# 110815-2138 - First build -# 120224-0910 - Added HTML display option with bar graphs -# 130414-0129 - Added report logging -# 130425-2113 - Added status flag summaries and other formatting cleanup -# 130425-2353 - Fixed bug with subtracting unsigned columns in SQL -# 130621-2016 - Added filtering of input to prevent SQL injection attacks and new user auth -# 130902-0743 - Changed to mysqli PHP functions -# 140108-0749 - Added webserver and hostname to report logging -# 140328-0005 - Converted division calculations to use MathZDC function -# 141114-0848 - Finalized adding QXZ translation to all admin files -# 141230-1516 - Added code for on-the-fly language translations display -# 150516-1312 - Fixed Javascript element problem, Issue #857 -# 151219-0107 - Added option for searching archived data -# 160227-1059 - Uniform form format -# 160714-2348 - Added and tested ChartJS features for more aesthetically appealing graphs -# 170227-1720 - Fix for default HTML report format, issue #997 -# 170409-1555 - Added IP List validation code -# 170829-0040 - Added screen color settings -# 171012-2015 - Fixed javascript/apache errors with graphs -# 180807-1204 - Fixed log query issue -# 191013-0832 - Fixes for PHP7 -# - -$startMS = microtime(); - -require("dbconnect_mysqli.php"); -require("functions.php"); - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} - elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} -if (isset($_GET["end_date_D"])) {$end_date_D=$_GET["end_date_D"];} - elseif (isset($_POST["end_date_D"])) {$end_date_D=$_POST["end_date_D"];} -if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} - elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} -if (isset($_GET["end_date_T"])) {$end_date_T=$_GET["end_date_T"];} - elseif (isset($_POST["end_date_T"])) {$end_date_T=$_POST["end_date_T"];} -if (isset($_GET["group"])) {$group=$_GET["group"];} - elseif (isset($_POST["group"])) {$group=$_POST["group"];} -if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} - elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} -if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} - elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} -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"];} - -$report_name="Campaign Status List Report"; -$NOW_DATE = date("Y-m-d"); -if (!isset($group)) {$group=array();} -if (!isset($query_date_D)) {$query_date_D=$NOW_DATE;} -if (!isset($end_date_D)) {$end_date_D=$NOW_DATE;} -if (!isset($query_date_T)) {$query_date_T="00:00:00";} -if (!isset($end_date_T)) {$end_date_T="23:59:59";} - -############################################# -##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $non_latin = $row[0]; - $outbound_autodial_active = $row[1]; - $slave_db_server = $row[2]; - $reports_use_slave_db = $row[3]; - $SSenable_languages = $row[4]; - $SSlanguage_method = $row[5]; - $SSreport_default_format = $row[6]; - } -##### END SETTINGS LOOKUP ##### -########################################### -if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} - -### ARCHIVED DATA CHECK CONFIGURATION -$archives_available="N"; -$log_tables_array=array("vicidial_log", "vicidial_closer_log", "vicidial_agent_log"); -for ($t=0; $t 0) - { - $row=mysqli_fetch_row($rslt); - $VUselected_language = $row[0]; - } - -$auth=0; -$reports_auth=0; -$admin_auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth > 0) - { - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $admin_auth=$row[0]; - - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $reports_auth=$row[0]; - - if ($reports_auth < 1) - { - $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ( ($reports_auth > 0) and ($admin_auth < 1) ) - { - $ADD=999999; - $reports_only_user=1; - } - } -else - { - $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ($auth_message == 'IPBLOCK') - { - $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - -##### BEGIN log visit to the vicidial_report_log table ##### -$LOGip = getenv("REMOTE_ADDR"); -$LOGbrowser = getenv("HTTP_USER_AGENT"); -$LOGscript_name = getenv("SCRIPT_NAME"); -$LOGserver_name = getenv("SERVER_NAME"); -$LOGserver_port = getenv("SERVER_PORT"); -$LOGrequest_uri = getenv("REQUEST_URI"); -$LOGhttp_referer = getenv("HTTP_REFERER"); -$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); -$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); -$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); -if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} -else {$LOGserver_port = ":$LOGserver_port";} -$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; - -$LOGhostname = php_uname('n'); -if (strlen($LOGhostname)<1) {$LOGhostname='X';} -if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} - -$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$webserver_id_ct = mysqli_num_rows($rslt); -if ($webserver_id_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $webserver_id = $row[0]; - } -else - { - ##### insert webserver entry - $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $affected_rows = mysqli_affected_rows($link); - $webserver_id = mysqli_insert_id($link); - } - -$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$report_log_id = mysqli_insert_id($link); -##### END log visit to the vicidial_report_log table ##### - -if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) - { - mysqli_close($link); - $use_slave_server=1; - $db_source = 'S'; - require("dbconnect_mysqli.php"); - $HTML_text.="\n"; - } - -$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; -if ($DB) {$HTML_text.="|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGuser_group = $row[0]; - -$stmt="SELECT allowed_campaigns,allowed_reports from vicidial_user_groups where user_group='$LOGuser_group';"; -if ($DB) {$HTML_text.="|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGallowed_campaigns = $row[0]; -$LOGallowed_reports = $row[1]; - -if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) - { - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; - exit; - } - -$LOGallowed_campaignsSQL=''; -$whereLOGallowed_campaignsSQL=''; -if ( (!preg_match("/-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')"; - } -$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - $group_string .= "$group[$i]|"; - $i++; - } - -$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$campaigns_to_print = mysqli_num_rows($rslt); -$i=0; -$groups=array(); -while ($i < $campaigns_to_print) - { - $row=mysqli_fetch_row($rslt); - $groups[$i] =$row[0]; - if (preg_match("/-ALL/",$group_string) ) - {$group[$i] = $groups[$i];} - $i++; - } - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) - { - $group_string .= "$group[$i]|"; - $group_SQL .= "'$group[$i]',"; - $groupQS .= "&group[]=$group[$i]"; - } - $i++; - } - -if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) - {$group_SQL = "";} -else - { - $group_SQL = preg_replace("/,\$/",'',$group_SQL); - $group_SQL_str=$group_SQL; - $group_SQL = "and campaign_id IN($group_SQL)"; - } - -$query_date="$query_date_D $query_date_T"; -$end_date="$end_date_D $end_date_T"; - -require("screen_colors.php"); - -$NWB = "   \"HELP\""; - -$HTML_head.="\n"; -$HTML_head.="\n"; -$HTML_head.="\n"; - -$HTML_head.="\n"; -$HTML_head.="\n"; -$HTML_head.="\n"; -require("chart_button.php"); -$HTML_head.="\n"; -$HTML_head.="\n"; - -$HTML_head.="\n"; -$HTML_head.=""._QXZ("$report_name")."$group_S\n"; -$short_header=1; - -# require("admin_header.php"); - -$HTML_text.="
"; -$HTML_text.=""._QXZ("$report_name")." $NWB#campaign_status_list_report$NWE\n"; - -$HTML_text.="
\n"; -$HTML_text.="
"._QXZ("Dates").":
"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.=""; - -$HTML_text.="\n"; - -$HTML_text.="   "; - -$HTML_text.="
"._QXZ("to")."
"; - -$HTML_text.="\n"; - -$HTML_text.="   "; - -$HTML_text.="
"._QXZ("Campaigns").":
"; -$HTML_text.="\n"; - -$HTML_text.="
 \n"; -$HTML_text.="\n"; -$HTML_text.=_QXZ("Display as").":
"; -$HTML_text.="\n

"; - -if ($archives_available=="Y") - { - $HTML_text.=""._QXZ("Search archived data")."

\n"; - } - -$HTML_text.="\n"; -$HTML_text.="
        "; - -$HTML_text.="          \n"; -$HTML_text.=""._QXZ("DOWNLOAD")." |"; -$HTML_text.=" "._QXZ("REPORTS")." \n"; -$HTML_text.="\n"; -$HTML_text.="
"; -$HTML_text.="
\n\n"; - -$HTML_text.="
";
-$i=0;
-$group_string='|';
-$group_ct = count($group);
-$JS_text.="\n";
-
-if ($report_display_type=="HTML")
-	{
-	$HTML_text.=$GRAPH.$JS_text;
-	}
-else
-	{
-	$HTML_text.=$ASCII_text;
-	}
-
-$HTML_text.="
"; - -if ($file_download>0) - { - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "AST_campaign_status_$US$FILE_TIME.csv"; - $CSV_text=preg_replace('/\n +,/', ',', $CSV_text); - $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); - $CSV_text=preg_replace('/\" +/', '"', $CSV_text); - - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - // It will be called LIST_101_20090209-121212.txt - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - } -else - { - header("Content-type: text/html; charset=utf-8"); - - echo $HTML_head; - require("admin_header.php"); - echo $HTML_text; - flush(); - } - -if ($db_source == 'S') - { - mysqli_close($link); - $use_slave_server=0; - $db_source = 'M'; - require("dbconnect_mysqli.php"); - } - -$endMS = microtime(); -$startMSary = explode(" ",$startMS); -$endMSary = explode(" ",$endMS); -$runS = ($endMSary[0] - $startMSary[0]); -$runM = ($endMSary[1] - $startMSary[1]); -$TOTALrun = ($runS + $runM); - -$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); - -exit; - -?> + LICENSE: AGPLv2 +# +# CHANGES +# +# 110815-2138 - First build +# 120224-0910 - Added HTML display option with bar graphs +# 130414-0129 - Added report logging +# 130425-2113 - Added status flag summaries and other formatting cleanup +# 130425-2353 - Fixed bug with subtracting unsigned columns in SQL +# 130621-2016 - Added filtering of input to prevent SQL injection attacks and new user auth +# 130902-0743 - Changed to mysqli PHP functions +# 140108-0749 - Added webserver and hostname to report logging +# 140328-0005 - Converted division calculations to use MathZDC function +# 141114-0848 - Finalized adding QXZ translation to all admin files +# 141230-1516 - Added code for on-the-fly language translations display +# 150516-1312 - Fixed Javascript element problem, Issue #857 +# 151219-0107 - Added option for searching archived data +# 160227-1059 - Uniform form format +# 160714-2348 - Added and tested ChartJS features for more aesthetically appealing graphs +# 170227-1720 - Fix for default HTML report format, issue #997 +# 170409-1555 - Added IP List validation code +# 170829-0040 - Added screen color settings +# 171012-2015 - Fixed javascript/apache errors with graphs +# 180807-1204 - Fixed log query issue +# 191013-0832 - Fixes for PHP7 +# + +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} + elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} +if (isset($_GET["end_date_D"])) {$end_date_D=$_GET["end_date_D"];} + elseif (isset($_POST["end_date_D"])) {$end_date_D=$_POST["end_date_D"];} +if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} + elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} +if (isset($_GET["end_date_T"])) {$end_date_T=$_GET["end_date_T"];} + elseif (isset($_POST["end_date_T"])) {$end_date_T=$_POST["end_date_T"];} +if (isset($_GET["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} + elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} + elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} +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"];} + +$report_name="Campaign Status List Report"; +$NOW_DATE = date("Y-m-d"); +if (!isset($group)) {$group=array();} +if (!isset($query_date_D)) {$query_date_D=$NOW_DATE;} +if (!isset($end_date_D)) {$end_date_D=$NOW_DATE;} +if (!isset($query_date_T)) {$query_date_T="00:00:00";} +if (!isset($end_date_T)) {$end_date_T="23:59:59";} + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $SSenable_languages = $row[4]; + $SSlanguage_method = $row[5]; + $SSreport_default_format = $row[6]; + } +##### END SETTINGS LOOKUP ##### +########################################### +if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} + +### ARCHIVED DATA CHECK CONFIGURATION +$archives_available="N"; +$log_tables_array=array("vicidial_log", "vicidial_closer_log", "vicidial_agent_log"); +for ($t=0; $t 0) + { + $row=mysqli_fetch_row($rslt); + $VUselected_language = $row[0]; + } + +$auth=0; +$reports_auth=0; +$admin_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $admin_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + if ($reports_auth < 1) + { + $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( ($reports_auth > 0) and ($admin_auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +##### BEGIN log visit to the vicidial_report_log table ##### +$LOGip = getenv("REMOTE_ADDR"); +$LOGbrowser = getenv("HTTP_USER_AGENT"); +$LOGscript_name = getenv("SCRIPT_NAME"); +$LOGserver_name = getenv("SERVER_NAME"); +$LOGserver_port = getenv("SERVER_PORT"); +$LOGrequest_uri = getenv("REQUEST_URI"); +$LOGhttp_referer = getenv("HTTP_REFERER"); +$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); +$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); +$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); +if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} +else {$LOGserver_port = ":$LOGserver_port";} +$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; + +$LOGhostname = php_uname('n'); +if (strlen($LOGhostname)<1) {$LOGhostname='X';} +if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} + +$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$webserver_id_ct = mysqli_num_rows($rslt); +if ($webserver_id_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $webserver_id = $row[0]; + } +else + { + ##### insert webserver entry + $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $affected_rows = mysqli_affected_rows($link); + $webserver_id = mysqli_insert_id($link); + } + +$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$report_log_id = mysqli_insert_id($link); +##### END log visit to the vicidial_report_log table ##### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysqli_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect_mysqli.php"); + $HTML_text.="\n"; + } + +$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {$HTML_text.="|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGuser_group = $row[0]; + +$stmt="SELECT allowed_campaigns,allowed_reports from vicidial_user_groups where user_group='$LOGuser_group';"; +if ($DB) {$HTML_text.="|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGallowed_campaigns = $row[0]; +$LOGallowed_reports = $row[1]; + +if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) + { + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; + exit; + } + +$LOGallowed_campaignsSQL=''; +$whereLOGallowed_campaignsSQL=''; +if ( (!preg_match("/-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')"; + } +$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + $group_string .= "$group[$i]|"; + $i++; + } + +$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$campaigns_to_print = mysqli_num_rows($rslt); +$i=0; +$groups=array(); +while ($i < $campaigns_to_print) + { + $row=mysqli_fetch_row($rslt); + $groups[$i] =$row[0]; + if (preg_match("/-ALL/",$group_string) ) + {$group[$i] = $groups[$i];} + $i++; + } + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) + { + $group_string .= "$group[$i]|"; + $group_SQL .= "'$group[$i]',"; + $groupQS .= "&group[]=$group[$i]"; + } + $i++; + } + +if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) + {$group_SQL = "";} +else + { + $group_SQL = preg_replace("/,\$/",'',$group_SQL); + $group_SQL_str=$group_SQL; + $group_SQL = "and campaign_id IN($group_SQL)"; + } + +$query_date="$query_date_D $query_date_T"; +$end_date="$end_date_D $end_date_T"; + +require("screen_colors.php"); + +$NWB = "   \"HELP\""; + +$HTML_head.="\n"; +$HTML_head.="\n"; +$HTML_head.="\n"; + +$HTML_head.="\n"; +$HTML_head.="\n"; +$HTML_head.="\n"; +require("chart_button.php"); +$HTML_head.="\n"; +$HTML_head.="\n"; + +$HTML_head.="\n"; +$HTML_head.=""._QXZ("$report_name")."$group_S\n"; +$short_header=1; + +# require("admin_header.php"); + +$HTML_text.="
"; +$HTML_text.=""._QXZ("$report_name")." $NWB#campaign_status_list_report$NWE\n"; + +$HTML_text.="
\n"; +$HTML_text.="
"._QXZ("Dates").":
"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.=""; + +$HTML_text.="\n"; + +$HTML_text.="   "; + +$HTML_text.="
"._QXZ("to")."
"; + +$HTML_text.="\n"; + +$HTML_text.="   "; + +$HTML_text.="
"._QXZ("Campaigns").":
"; +$HTML_text.="\n"; + +$HTML_text.="
 \n"; +$HTML_text.="\n"; +$HTML_text.=_QXZ("Display as").":
"; +$HTML_text.="\n

"; + +if ($archives_available=="Y") + { + $HTML_text.=""._QXZ("Search archived data")."

\n"; + } + +$HTML_text.="\n"; +$HTML_text.="
        "; + +$HTML_text.="          \n"; +$HTML_text.=""._QXZ("DOWNLOAD")." |"; +$HTML_text.=" "._QXZ("REPORTS")." \n"; +$HTML_text.="\n"; +$HTML_text.="
"; +$HTML_text.="
\n\n"; + +$HTML_text.="
";
+$i=0;
+$group_string='|';
+$group_ct = count($group);
+$JS_text.="\n";
+
+if ($report_display_type=="HTML")
+	{
+	$HTML_text.=$GRAPH.$JS_text;
+	}
+else
+	{
+	$HTML_text.=$ASCII_text;
+	}
+
+$HTML_text.="
"; + +if ($file_download>0) + { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_campaign_status_$US$FILE_TIME.csv"; + $CSV_text=preg_replace('/\n +,/', ',', $CSV_text); + $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); + $CSV_text=preg_replace('/\" +/', '"', $CSV_text); + + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + } +else + { + header("Content-type: text/html; charset=utf-8"); + + echo $HTML_head; + require("admin_header.php"); + echo $HTML_text; + flush(); + } + +if ($db_source == 'S') + { + mysqli_close($link); + $use_slave_server=0; + $db_source = 'M'; + require("dbconnect_mysqli.php"); + } + +$endMS = microtime(); +$startMSary = explode(" ",$startMS); +$endMSary = explode(" ",$endMS); +$runS = ($endMSary[0] - $startMSary[0]); +$runM = ($endMSary[1] - $startMSary[1]); +$TOTALrun = ($runS + $runM); + +$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); + +exit; + +?> diff --git a/agc_2-X/trunk/www/vicidial/AST_dial_log_report.php b/agc_2-X/trunk/www/vicidial/AST_dial_log_report.php index 3292b4fd..fddb1216 100644 --- a/agc_2-X/trunk/www/vicidial/AST_dial_log_report.php +++ b/agc_2-X/trunk/www/vicidial/AST_dial_log_report.php @@ -1,710 +1,710 @@ - LICENSE: AGPLv2 -# -# CHANGES -# 130709-1346 - First build -# 130831-0927 - Changed to mysqli PHP functions -# 140108-0744 - Added webserver and hostname to report logging -# 141114-0844 - Finalized adding QXZ translation to all admin files -# 141230-1510 - Added code for on-the-fly language translations display -# 170409-1534 - Added IP List validation code -# 170821-2323 - Added HTML formatting -# 170829-0040 - Added screen color settings -# 191013-0818 - Fixes for PHP7 -# 210129-1010 - Added archive search option, issue #1222 -# - -$startMS = microtime(); - -require("dbconnect_mysqli.php"); -require("functions.php"); - -$report_name='Dial Log Report'; - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} - elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} - elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} -if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} - elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} -if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} - elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} -if (isset($_GET["hangup_cause"])) {$hangup_cause=$_GET["hangup_cause"];} - elseif (isset($_POST["hangup_cause"])) {$hangup_cause=$_POST["hangup_cause"];} -if (isset($_GET["sip_hangup_cause"])) {$sip_hangup_cause=$_GET["sip_hangup_cause"];} - elseif (isset($_POST["sip_hangup_cause"])) {$sip_hangup_cause=$_POST["sip_hangup_cause"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["lower_limit"])) {$lower_limit=$_GET["lower_limit"];} - elseif (isset($_POST["lower_limit"])) {$lower_limit=$_POST["lower_limit"];} -if (isset($_GET["upper_limit"])) {$upper_limit=$_GET["upper_limit"];} - elseif (isset($_POST["upper_limit"])) {$upper_limit=$_POST["upper_limit"];} -if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];} - elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];} -if (isset($_GET["extension"])) {$extension=$_GET["extension"];} - elseif (isset($_POST["extension"])) {$extension=$_POST["extension"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["submit"])) {$submit=$_GET["submit"];} - elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} -if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} -if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} - elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} -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"];} - -#### SIP response code directory -$sip_response_directory = array( - 0 => "", - 100 => _QXZ("Trying"), - 180 => _QXZ("Ringing"), - 181 => _QXZ("Call is Being Forwarded"), - 182 => _QXZ("Queued"), - 183 => _QXZ("Session in Progress"), - 199 => _QXZ("Early Dialog Terminated"), - 200 => _QXZ("OK"), - 202 => _QXZ("Accepted"), - 204 => _QXZ("No Notification"), - 300 => _QXZ("Multiple Choices"), - 301 => _QXZ("Moved Permanently"), - 301 => _QXZ("Moved Temporarily"), - 302 => _QXZ("Moved Temporarily"), - 305 => _QXZ("Use Proxy"), - 380 => _QXZ("Alternative Service"), - 400 => _QXZ("Bad Request"), - 401 => _QXZ("Unauthorized"), - 402 => _QXZ("Payment Required"), - 403 => _QXZ("Forbidden"), - 404 => _QXZ("Not Found"), - 405 => _QXZ("Method Not Allowed"), - 406 => _QXZ("Not Acceptable"), - 407 => _QXZ("Proxy Authentication Required"), - 408 => _QXZ("Request Timeout"), - 409 => _QXZ("Conflict"), - 410 => _QXZ("Gone"), - 411 => _QXZ("Length Required"), - 412 => _QXZ("Conditional Request Failed"), - 413 => _QXZ("Request Entity Too Large"), - 414 => _QXZ("Request-URI Too Long"), - 415 => _QXZ("Unsupported Media Type"), - 416 => _QXZ("Unsupported URI Scheme"), - 417 => _QXZ("Unknown Resource-Priority"), - 420 => _QXZ("Bad Extension"), - 421 => _QXZ("Extension Required"), - 422 => _QXZ("Session Interval Too Small"), - 423 => _QXZ("Interval Too Brief"), - 424 => _QXZ("Bad Location Information"), - 428 => _QXZ("Use Identity Header"), - 429 => _QXZ("Provide Referrer Identity"), - 430 => _QXZ("Flow Failed"), - 433 => _QXZ("Anonymity Disallowed"), - 436 => _QXZ("Bad Identity-Info"), - 437 => _QXZ("Unsupported Certificate"), - 438 => _QXZ("Invalid Identity Header"), - 439 => _QXZ("First Hop Lacks Outbound Support"), - 470 => _QXZ("Consent Needed"), - 480 => _QXZ("Temporarily Unavailable"), - 481 => _QXZ("Call/Transaction Does Not Exist"), - 482 => _QXZ("Loop Detected."), - 483 => _QXZ("Too Many Hops"), - 484 => _QXZ("Address Incomplete"), - 485 => _QXZ("Ambiguous"), - 486 => _QXZ("Busy Here"), - 487 => _QXZ("Request Terminated"), - 488 => _QXZ("Not Acceptable Here"), - 489 => _QXZ("Bad Event"), - 491 => _QXZ("Request Pending"), - 493 => _QXZ("Undecipherable"), - 494 => _QXZ("Security Agreement Required"), - 500 => _QXZ("Server Internal Error"), - 501 => _QXZ("Not Implemented"), - 502 => _QXZ("Bad Gateway"), - 503 => _QXZ("Service Unavailable"), - 504 => _QXZ("Server Time-out"), - 505 => _QXZ("Version Not Supported"), - 513 => _QXZ("Message Too Large"), - 580 => _QXZ("Precondition Failure"), - 600 => _QXZ("Busy Everywhere"), - 603 => _QXZ("Decline"), - 604 => _QXZ("Does Not Exist Anywhere"), - 606 => _QXZ("Not Acceptable"), -); - -$master_sip_response_directory=array(); -$master_sip_response_verbiage_directory=array(); -$i=0; -# while (list($key, $val)=each($sip_response_directory)) -foreach ($sip_response_directory as $key => $val) - { - $master_sip_response_directory[$i]=$key; - $master_sip_response_verbiage_directory[$i]=$val; - $i++; - } -$sip_responses_to_print=count($master_sip_response_directory); - -$NOW_DATE = date("Y-m-d"); - -if (strlen($query_date_D) < 6) {$query_date_D = "00:00:00";} -if (strlen($query_date_T) < 6) {$query_date_T = "23:59:59";} -if (!isset($query_date)) {$query_date = $NOW_DATE;} -if (!isset($server_ip)) {$server_ip = array();} -if (!isset($sip_hangup_cause)) {$sip_hangup_cause = array();} - -############################################# -##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method FROM system_settings;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$MAIN.="$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $non_latin = $row[0]; - $outbound_autodial_active = $row[1]; - $slave_db_server = $row[2]; - $reports_use_slave_db = $row[3]; - $SSenable_languages = $row[4]; - $SSlanguage_method = $row[5]; - } -##### END SETTINGS LOOKUP ##### -########################################### - -### ARCHIVED DATA CHECK CONFIGURATION -$archives_available="N"; -$log_tables_array=array("vicidial_dial_log"); -for ($t=0; $t 0) - { - $row=mysqli_fetch_row($rslt); - $VUselected_language = $row[0]; - } - -$auth=0; -$reports_auth=0; -$admin_auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth > 0) - { - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7;"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $admin_auth=$row[0]; - - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $reports_auth=$row[0]; - - if ($reports_auth < 1) - { - $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ( ($reports_auth > 0) and ($admin_auth < 1) ) - { - $ADD=999999; - $reports_only_user=1; - } - } -else - { - $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ($auth_message == 'IPBLOCK') - { - $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - - -##### BEGIN log visit to the vicidial_report_log table ##### -$LOGip = getenv("REMOTE_ADDR"); -$LOGbrowser = getenv("HTTP_USER_AGENT"); -$LOGscript_name = getenv("SCRIPT_NAME"); -$LOGserver_name = getenv("SERVER_NAME"); -$LOGserver_port = getenv("SERVER_PORT"); -$LOGrequest_uri = getenv("REQUEST_URI"); -$LOGhttp_referer = getenv("HTTP_REFERER"); -$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); -$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); -$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); -if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} -else {$LOGserver_port = ":$LOGserver_port";} -$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; - -$LOGhostname = php_uname('n'); -if (strlen($LOGhostname)<1) {$LOGhostname='X';} -if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} - -$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$webserver_id_ct = mysqli_num_rows($rslt); -if ($webserver_id_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $webserver_id = $row[0]; - } -else - { - ##### insert webserver entry - $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $affected_rows = mysqli_affected_rows($link); - $webserver_id = mysqli_insert_id($link); - } - -$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$query_date, $end_date, $lower_limit, $upper_limit, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$report_log_id = mysqli_insert_id($link); -##### END log visit to the vicidial_report_log table ##### - - -if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) - { - mysqli_close($link); - $use_slave_server=1; - $db_source = 'S'; - require("dbconnect_mysqli.php"); - $MAIN.="\n"; - } - -$server_ip_string='|'; -$server_ip_ct = count($server_ip); -$i=0; -while($i < $server_ip_ct) - { - $server_ip_string .= "$server_ip[$i]|"; - $i++; - } - -$server_stmt="select server_ip,server_description from servers where active_asterisk_server='Y' order by server_ip asc;"; -$server_rslt=mysql_to_mysqli($server_stmt, $link); -$servers_to_print=mysqli_num_rows($server_rslt); -$i=0; -$LISTserverIPs=array(); -$LISTserver_names=array(); -while ($i < $servers_to_print) - { - $row=mysqli_fetch_row($server_rslt); - $LISTserverIPs[$i] = $row[0]; - $LISTserver_names[$i] = $row[1]; - if (preg_match('/\-ALL/',$server_ip_string) ) - { - $server_ip[$i] = $LISTserverIPs[$i]; - } - $i++; - } - -$i=0; -$server_ips_string='|'; -$server_ip_ct = count($server_ip); -while($i < $server_ip_ct) - { - if ( (strlen($server_ip[$i]) > 0) and (preg_match("/\|$server_ip[$i]\|/",$server_ip_string)) ) - { - $server_ips_string .= "$server_ip[$i]|"; - $server_ip_SQL .= "'$server_ip[$i]',"; - $server_ipQS .= "&server_ip[]=$server_ip[$i]"; - } - $i++; - } - -if ( (preg_match('/\-\-ALL\-\-/',$server_ip_string) ) or ($server_ip_ct < 1) ) - { - $server_ip_SQL = ""; - $server_rpt_string="- "._QXZ("ALL servers")." "; - if (preg_match('/\-\-ALL\-\-/',$server_ip_string)) {$server_ipQS="&server_ip[]=--ALL--";} - } -else - { - $server_ip_SQL = preg_replace('/,$/i', '',$server_ip_SQL); - $server_ip_SQL = "and server_ip IN($server_ip_SQL)"; - $server_rpt_string="- "._QXZ("server(s)")." ".preg_replace('/\|/', ", ", substr($server_ip_string, 1, -1)); - } -if (strlen($server_ip_SQL)<3) {$server_ip_SQL="";} - -$sip_hangup_cause_string='|'; -$sip_hangup_cause_ct = count($sip_hangup_cause); -$i=0; -while($i < $sip_hangup_cause_ct) - { - $sip_hangup_cause_string .= "$sip_hangup_cause[$i]|"; - $i++; - } - -$sip_hangup_causes_string='|'; - -$i=0; -$sip_hangup_cause_SQL=""; -while($i < $sip_hangup_cause_ct) - { - if ( (strlen($sip_hangup_cause[$i]) > 0) and (preg_match("/\|$sip_hangup_cause[$i]\|/",$sip_hangup_cause_string)) ) - { - $sip_hangup_causes_string .= "$sip_hangup_cause[$i]|"; - $sip_hangup_causeQS .= "&sip_hangup_cause[]=$sip_hangup_cause[$i]"; - $sip_hangup_cause_SQL.="$sip_hangup_cause[$i],"; - } - $i++; - } - -if ( (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string) ) or ($sip_hangup_cause_ct < 1) ) - { - $HC_rpt_string="- "._QXZ("ALL SIP hangup causes")." "; - if (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string)) - { - $sip_hangup_causeQS="&sip_hangup_cause[]=--ALL--"; - $sip_hangup_cause_SQL=""; - } - } -else - { - $sip_hangup_causes_string=preg_replace('/\!/', "-", $sip_hangup_causes_string); - $HC_rpt_string=_QXZ("AND SIP hangup cause(s)")." ".preg_replace('/\|/', ", ", substr($sip_hangup_causes_string, 1, -1)); - } -$sip_hangup_cause_SQL = preg_replace('/,$/i', '',$sip_hangup_cause_SQL); -if (strlen($sip_hangup_cause_SQL)>0) {$sip_hangup_cause_SQL="and sip_hangup_cause in ($sip_hangup_cause_SQL)";} - -require("screen_colors.php"); - -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.=""._QXZ("$report_name")."\n"; - -$short_header=1; - -$MAIN.="
"; -$MAIN.="
\n"; -$MAIN.=""; - -$MAIN.=""; - -$MAIN.="
\n"; -$MAIN.="\n"; -$MAIN.=_QXZ("Date").":\n"; -$MAIN.=""; -$MAIN.="\n"; - -$MAIN.="

"; - -$MAIN.="
"._QXZ("to")."
"; - -$MAIN.="
"._QXZ("Server IP").":
\n"; -$MAIN.="
"._QXZ("SIP Response").":
"; -$MAIN.=""; -$MAIN.="
\n"; -$MAIN.=_QXZ("Display as:")."
"; -$MAIN.="

\n"; - -if ($archives_available=="Y") - { - $MAIN.=""._QXZ("Search archived data")."

\n"; - } - -$MAIN.="

\n"; -$MAIN.="
\n"; -$TEXT.="
\n";
-
-if ($SUBMIT && $query_date) {
-	$stmt="SELECT * From ".$vicidial_dial_log_table." where call_date>='$query_date $query_date_D' and call_date<='$query_date $query_date_T' $server_ip_SQL $sip_hangup_cause_SQL order by call_date asc";
-	$rslt=mysql_to_mysqli($stmt, $link);
-
-	if (!$lower_limit) {$lower_limit=1;}
-	if ($lower_limit+999>=mysqli_num_rows($rslt)) {$upper_limit=($lower_limit+mysqli_num_rows($rslt)%1000)-1;} else {$upper_limit=$lower_limit+999;}
-	$TEXT.="--- "._QXZ("DIAL LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string\n --- "._QXZ("RECORDS")." #$lower_limit-$upper_limit               ["._QXZ("DOWNLOAD")."]\n";
-	$CSV_text="\""._QXZ("CALLER CODE")."\",\""._QXZ("LEAD ID")."\",\""._QXZ("SERVER IP")."\",\""._QXZ("CALL DATE")."\",\""._QXZ("EXTENSION")."\",\""._QXZ("CHANNEL")."\",\""._QXZ("CONTEXT")."\",\""._QXZ("TIMEOUT")."\",\""._QXZ("OUTBOUND CID")."\",\""._QXZ("SIP HANGUP CAUSE")."\",\""._QXZ("UNIQUE ID")."\",\""._QXZ("SIP HANGUP REASON")."\"\n";
-
-	$HTML.="
"; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - - $dial_log_rpt ="+----------------------+-----------+-----------------+---------------------+----------------------+----------------------------------------------------+----------------------+---------+------------------------------------------+--------+----------------------+----------------------------------------------------+\n"; - $dial_log_rpt.="| | | | | | | | | | "._QXZ("SIP",6)." | | |\n"; - $dial_log_rpt.="| | | | | | | | | | "._QXZ("HANGUP",6)." | | |\n"; - $dial_log_rpt.="| "._QXZ("CALLER CODE",20)." | "._QXZ("LEAD ID",9)." | "._QXZ("SERVER IP",15)." | "._QXZ("CALL DATE",19)." | "._QXZ("EXTENSION",20)." | "._QXZ("CHANNEL",50)." | "._QXZ("CONTEXT",20)." | "._QXZ("TIMEOUT",7)." | "._QXZ("OUTBOUND CID",40)." | "._QXZ("CAUSE",6)." | "._QXZ("UNIQUE ID",20)." | "._QXZ("SIP HANGUP REASON",50)." |\n"; - $dial_log_rpt.="+----------------------+-----------+-----------------+---------------------+----------------------+----------------------------------------------------+----------------------+---------+------------------------------------------+--------+----------------------+----------------------------------------------------+\n"; - if ($DB) {$dial_log_rpt.=$stmt."\n";} - - if(mysqli_num_rows($rslt)>0) { - $i=0; - while($row=mysqli_fetch_array($rslt)) { - $i++; - if (strlen($row["extension"])>20) {$row["extension"]=substr($row["extension"], 0, 17)."...";} - if (strlen($row["caller_code"])>20) {$row["caller_code"]=substr($row["caller_code"], 0, 17)."...";} - if (strlen($row["context"])>20) {$row["context"]=substr($row["context"], 0, 17)."...";} - if (strlen($row["outbound_cid"])>40) {$row["outbound_cid"]=substr($row["outbound_cid"], 0, 37)."...";} - if ($i>=$lower_limit && $i<=$upper_limit) { - if (strlen($row["channel"])>50) { - $dial_log_rpt.="| "; - $dial_log_rpt.=sprintf("%-20s",substr($row["caller_code"], 0, 20))." | "; - $dial_log_rpt.=sprintf("%-9s",$row["lead_id"])." | "; - $dial_log_rpt.=sprintf("%-15s",$row["server_ip"])." | "; - $dial_log_rpt.=sprintf("%-19s",$row["call_date"])." | "; - $dial_log_rpt.=sprintf("%-20s", substr($row["extension"], 0, 20))." | "; - $dial_log_rpt.=sprintf("%-50s", substr($row["channel"], 0, 50))." | "; - $dial_log_rpt.=sprintf("%-20s", substr($row["context"], 0, 20))." | "; - $dial_log_rpt.=sprintf("%-7s",$row["timeout"])." | "; - $dial_log_rpt.=sprintf("%-40s", substr($row["outbound_cid"], 0, 40))." | "; - $dial_log_rpt.=sprintf("%-6s",$row["sip_hangup_cause"])." | "; - $dial_log_rpt.=sprintf("%-20s",$row["uniqueid"])." | "; - $dial_log_rpt.=sprintf("%-50s",$row["sip_hangup_reason"])." |\n"; - - $dial_log_rpt.="| "; - $dial_log_rpt.=sprintf("%-20s","")." | "; - $dial_log_rpt.=sprintf("%-9s","")." | "; - $dial_log_rpt.=sprintf("%-15s","")." | "; - $dial_log_rpt.=sprintf("%-19s","")." | "; - $dial_log_rpt.=sprintf("%-20s", "")." | "; - $dial_log_rpt.=sprintf("%-50s", substr($row["channel"], 50))." | "; - $dial_log_rpt.=sprintf("%-20s", "")." | "; - $dial_log_rpt.=sprintf("%-7s","")." | "; - $dial_log_rpt.=sprintf("%-40s", "")." | "; - $dial_log_rpt.=sprintf("%-6s","")." | "; - $dial_log_rpt.=sprintf("%-20s","")." | "; - $dial_log_rpt.=sprintf("%-50s","")." |\n"; - } else { - $dial_log_rpt.="| "; - $dial_log_rpt.=sprintf("%-20s",substr($row["caller_code"], 0, 20))." | "; - $dial_log_rpt.=sprintf("%-9s",$row["lead_id"])." | "; - $dial_log_rpt.=sprintf("%-15s",$row["server_ip"])." | "; - $dial_log_rpt.=sprintf("%-19s",$row["call_date"])." | "; - $dial_log_rpt.=sprintf("%-20s", substr($row["extension"], 0, 20))." | "; - $dial_log_rpt.=sprintf("%-50s", substr($row["channel"], 0, 50))." | "; - $dial_log_rpt.=sprintf("%-20s", substr($row["context"], 0, 20))." | "; - $dial_log_rpt.=sprintf("%-7s",$row["timeout"])." | "; - $dial_log_rpt.=sprintf("%-40s", substr($row["outbound_cid"], 0, 40))." | "; - $dial_log_rpt.=sprintf("%-6s",$row["sip_hangup_cause"])." | "; - $dial_log_rpt.=sprintf("%-20s",$row["uniqueid"])." | "; - $dial_log_rpt.=sprintf("%-50s",$row["sip_hangup_reason"])." |\n"; - } - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - } - $CSV_text.="\"$row[caller_code]\",\"$row[lead_id]\",\"$row[server_ip]\",\"$row[call_date]\",\"$row[extension]\",\"$row[channel]\",\"$row[context]\",\"$row[timeout]\",\"$row[outbound_cid]\",\"$row[sip_hangup_cause]\",\"$row[uniqueid]\",\"$row[sip_hangup_reason]\"\n"; - } - } else { - $dial_log_rpt.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; - $HTML.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; - } - $dial_log_rpt.="+----------------------+-----------+-----------------+---------------------+----------------------+----------------------------------------------------+----------------------+---------+------------------------------------------+--------+----------------------+----------------------------------------------------+\n"; - - $dial_log_rpt_hf=""; - $ll=$lower_limit-1000; - $HTML.=""; - if ($ll>=1) { - $dial_log_rpt_hf.="[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."]"; - $HTML.=""; - } else { - $dial_log_rpt_hf.=sprintf("%-23s", " "); - $HTML.="
"._QXZ("DIAL LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string, "._QXZ("RECORDS")." #$lower_limit-$upper_limit["._QXZ("DOWNLOAD")."]
"._QXZ("CALLER CODE").""._QXZ("LEAD ID").""._QXZ("SERVER IP").""._QXZ("CALL DATE").""._QXZ("EXTENSION").""._QXZ("CHANNEL").""._QXZ("CONTEXT").""._QXZ("TIMEOUT").""._QXZ("OUTBOUND CID").""._QXZ("SIP HANGUP CAUSE").""._QXZ("UNIQUE ID").""._QXZ("SIP HANGUP REASON")."
".$row["caller_code"]."".$row["lead_id"]."".$row["server_ip"]."".$row["call_date"]."".$row["extension"]."".$row["channel"]."".$row["context"]."".$row["timeout"]."".$row["outbound_cid"]."".$row["sip_hangup_cause"]."".$row["uniqueid"]."".$row["sip_hangup_reason"]."
[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."] "; - } - $dial_log_rpt_hf.=sprintf("%-145s", " "); - - if (($lower_limit+1000)=mysqli_num_rows($rslt)) {$max_limit=mysqli_num_rows($rslt)-$upper_limit;} else {$max_limit=1000;} - $dial_log_rpt_hf.="["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; - $HTML.="["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; - } else { - $dial_log_rpt_hf.=sprintf("%23s", " "); - $HTML.=" "; - } - $dial_log_rpt_hf.="\n"; - $TEXT.=$dial_log_rpt_hf.$dial_log_rpt.$dial_log_rpt_hf; - - $TEXT.="\n"; - $HTML.="
"; - - if ($report_display_type=="HTML") { - $MAIN.=$HTML; - } else { - $MAIN.=$TEXT; - } -} - if ($file_download>0) { - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "AST_dial_log_report_$US$FILE_TIME.csv"; - $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); - $CSV_text=preg_replace('/\" +/', '"', $CSV_text); - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - - // It will be called LIST_101_20090209-121212.txt - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - - } else { - echo $HEADER; - require("admin_header.php"); - echo $MAIN; - } - -$endMS = microtime(); -$startMSary = explode(" ",$startMS); -$endMSary = explode(" ",$endMS); -$runS = ($endMSary[0] - $startMSary[0]); -$runM = ($endMSary[1] - $startMSary[1]); -$TOTALrun = ($runS + $runM); - -$END_TIME=date("U"); - -#print "Total run time: ".($END_TIME-$START_TIME); - -$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); - -?> + LICENSE: AGPLv2 +# +# CHANGES +# 130709-1346 - First build +# 130831-0927 - Changed to mysqli PHP functions +# 140108-0744 - Added webserver and hostname to report logging +# 141114-0844 - Finalized adding QXZ translation to all admin files +# 141230-1510 - Added code for on-the-fly language translations display +# 170409-1534 - Added IP List validation code +# 170821-2323 - Added HTML formatting +# 170829-0040 - Added screen color settings +# 191013-0818 - Fixes for PHP7 +# 210129-1010 - Added archive search option, issue #1222 +# + +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$report_name='Dial Log Report'; + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} + elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} +if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} + elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} +if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} + elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} +if (isset($_GET["hangup_cause"])) {$hangup_cause=$_GET["hangup_cause"];} + elseif (isset($_POST["hangup_cause"])) {$hangup_cause=$_POST["hangup_cause"];} +if (isset($_GET["sip_hangup_cause"])) {$sip_hangup_cause=$_GET["sip_hangup_cause"];} + elseif (isset($_POST["sip_hangup_cause"])) {$sip_hangup_cause=$_POST["sip_hangup_cause"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["lower_limit"])) {$lower_limit=$_GET["lower_limit"];} + elseif (isset($_POST["lower_limit"])) {$lower_limit=$_POST["lower_limit"];} +if (isset($_GET["upper_limit"])) {$upper_limit=$_GET["upper_limit"];} + elseif (isset($_POST["upper_limit"])) {$upper_limit=$_POST["upper_limit"];} +if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];} + elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];} +if (isset($_GET["extension"])) {$extension=$_GET["extension"];} + elseif (isset($_POST["extension"])) {$extension=$_POST["extension"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} + elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} +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"];} + +#### SIP response code directory +$sip_response_directory = array( + 0 => "", + 100 => _QXZ("Trying"), + 180 => _QXZ("Ringing"), + 181 => _QXZ("Call is Being Forwarded"), + 182 => _QXZ("Queued"), + 183 => _QXZ("Session in Progress"), + 199 => _QXZ("Early Dialog Terminated"), + 200 => _QXZ("OK"), + 202 => _QXZ("Accepted"), + 204 => _QXZ("No Notification"), + 300 => _QXZ("Multiple Choices"), + 301 => _QXZ("Moved Permanently"), + 301 => _QXZ("Moved Temporarily"), + 302 => _QXZ("Moved Temporarily"), + 305 => _QXZ("Use Proxy"), + 380 => _QXZ("Alternative Service"), + 400 => _QXZ("Bad Request"), + 401 => _QXZ("Unauthorized"), + 402 => _QXZ("Payment Required"), + 403 => _QXZ("Forbidden"), + 404 => _QXZ("Not Found"), + 405 => _QXZ("Method Not Allowed"), + 406 => _QXZ("Not Acceptable"), + 407 => _QXZ("Proxy Authentication Required"), + 408 => _QXZ("Request Timeout"), + 409 => _QXZ("Conflict"), + 410 => _QXZ("Gone"), + 411 => _QXZ("Length Required"), + 412 => _QXZ("Conditional Request Failed"), + 413 => _QXZ("Request Entity Too Large"), + 414 => _QXZ("Request-URI Too Long"), + 415 => _QXZ("Unsupported Media Type"), + 416 => _QXZ("Unsupported URI Scheme"), + 417 => _QXZ("Unknown Resource-Priority"), + 420 => _QXZ("Bad Extension"), + 421 => _QXZ("Extension Required"), + 422 => _QXZ("Session Interval Too Small"), + 423 => _QXZ("Interval Too Brief"), + 424 => _QXZ("Bad Location Information"), + 428 => _QXZ("Use Identity Header"), + 429 => _QXZ("Provide Referrer Identity"), + 430 => _QXZ("Flow Failed"), + 433 => _QXZ("Anonymity Disallowed"), + 436 => _QXZ("Bad Identity-Info"), + 437 => _QXZ("Unsupported Certificate"), + 438 => _QXZ("Invalid Identity Header"), + 439 => _QXZ("First Hop Lacks Outbound Support"), + 470 => _QXZ("Consent Needed"), + 480 => _QXZ("Temporarily Unavailable"), + 481 => _QXZ("Call/Transaction Does Not Exist"), + 482 => _QXZ("Loop Detected."), + 483 => _QXZ("Too Many Hops"), + 484 => _QXZ("Address Incomplete"), + 485 => _QXZ("Ambiguous"), + 486 => _QXZ("Busy Here"), + 487 => _QXZ("Request Terminated"), + 488 => _QXZ("Not Acceptable Here"), + 489 => _QXZ("Bad Event"), + 491 => _QXZ("Request Pending"), + 493 => _QXZ("Undecipherable"), + 494 => _QXZ("Security Agreement Required"), + 500 => _QXZ("Server Internal Error"), + 501 => _QXZ("Not Implemented"), + 502 => _QXZ("Bad Gateway"), + 503 => _QXZ("Service Unavailable"), + 504 => _QXZ("Server Time-out"), + 505 => _QXZ("Version Not Supported"), + 513 => _QXZ("Message Too Large"), + 580 => _QXZ("Precondition Failure"), + 600 => _QXZ("Busy Everywhere"), + 603 => _QXZ("Decline"), + 604 => _QXZ("Does Not Exist Anywhere"), + 606 => _QXZ("Not Acceptable"), +); + +$master_sip_response_directory=array(); +$master_sip_response_verbiage_directory=array(); +$i=0; +# while (list($key, $val)=each($sip_response_directory)) +foreach ($sip_response_directory as $key => $val) + { + $master_sip_response_directory[$i]=$key; + $master_sip_response_verbiage_directory[$i]=$val; + $i++; + } +$sip_responses_to_print=count($master_sip_response_directory); + +$NOW_DATE = date("Y-m-d"); + +if (strlen($query_date_D) < 6) {$query_date_D = "00:00:00";} +if (strlen($query_date_T) < 6) {$query_date_T = "23:59:59";} +if (!isset($query_date)) {$query_date = $NOW_DATE;} +if (!isset($server_ip)) {$server_ip = array();} +if (!isset($sip_hangup_cause)) {$sip_hangup_cause = array();} + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$MAIN.="$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $SSenable_languages = $row[4]; + $SSlanguage_method = $row[5]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +### ARCHIVED DATA CHECK CONFIGURATION +$archives_available="N"; +$log_tables_array=array("vicidial_dial_log"); +for ($t=0; $t 0) + { + $row=mysqli_fetch_row($rslt); + $VUselected_language = $row[0]; + } + +$auth=0; +$reports_auth=0; +$admin_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7;"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $admin_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + if ($reports_auth < 1) + { + $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( ($reports_auth > 0) and ($admin_auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + + +##### BEGIN log visit to the vicidial_report_log table ##### +$LOGip = getenv("REMOTE_ADDR"); +$LOGbrowser = getenv("HTTP_USER_AGENT"); +$LOGscript_name = getenv("SCRIPT_NAME"); +$LOGserver_name = getenv("SERVER_NAME"); +$LOGserver_port = getenv("SERVER_PORT"); +$LOGrequest_uri = getenv("REQUEST_URI"); +$LOGhttp_referer = getenv("HTTP_REFERER"); +$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); +$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); +$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); +if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} +else {$LOGserver_port = ":$LOGserver_port";} +$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; + +$LOGhostname = php_uname('n'); +if (strlen($LOGhostname)<1) {$LOGhostname='X';} +if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} + +$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$webserver_id_ct = mysqli_num_rows($rslt); +if ($webserver_id_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $webserver_id = $row[0]; + } +else + { + ##### insert webserver entry + $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $affected_rows = mysqli_affected_rows($link); + $webserver_id = mysqli_insert_id($link); + } + +$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$query_date, $end_date, $lower_limit, $upper_limit, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$report_log_id = mysqli_insert_id($link); +##### END log visit to the vicidial_report_log table ##### + + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysqli_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect_mysqli.php"); + $MAIN.="\n"; + } + +$server_ip_string='|'; +$server_ip_ct = count($server_ip); +$i=0; +while($i < $server_ip_ct) + { + $server_ip_string .= "$server_ip[$i]|"; + $i++; + } + +$server_stmt="select server_ip,server_description from servers where active_asterisk_server='Y' order by server_ip asc;"; +$server_rslt=mysql_to_mysqli($server_stmt, $link); +$servers_to_print=mysqli_num_rows($server_rslt); +$i=0; +$LISTserverIPs=array(); +$LISTserver_names=array(); +while ($i < $servers_to_print) + { + $row=mysqli_fetch_row($server_rslt); + $LISTserverIPs[$i] = $row[0]; + $LISTserver_names[$i] = $row[1]; + if (preg_match('/\-ALL/',$server_ip_string) ) + { + $server_ip[$i] = $LISTserverIPs[$i]; + } + $i++; + } + +$i=0; +$server_ips_string='|'; +$server_ip_ct = count($server_ip); +while($i < $server_ip_ct) + { + if ( (strlen($server_ip[$i]) > 0) and (preg_match("/\|$server_ip[$i]\|/",$server_ip_string)) ) + { + $server_ips_string .= "$server_ip[$i]|"; + $server_ip_SQL .= "'$server_ip[$i]',"; + $server_ipQS .= "&server_ip[]=$server_ip[$i]"; + } + $i++; + } + +if ( (preg_match('/\-\-ALL\-\-/',$server_ip_string) ) or ($server_ip_ct < 1) ) + { + $server_ip_SQL = ""; + $server_rpt_string="- "._QXZ("ALL servers")." "; + if (preg_match('/\-\-ALL\-\-/',$server_ip_string)) {$server_ipQS="&server_ip[]=--ALL--";} + } +else + { + $server_ip_SQL = preg_replace('/,$/i', '',$server_ip_SQL); + $server_ip_SQL = "and server_ip IN($server_ip_SQL)"; + $server_rpt_string="- "._QXZ("server(s)")." ".preg_replace('/\|/', ", ", substr($server_ip_string, 1, -1)); + } +if (strlen($server_ip_SQL)<3) {$server_ip_SQL="";} + +$sip_hangup_cause_string='|'; +$sip_hangup_cause_ct = count($sip_hangup_cause); +$i=0; +while($i < $sip_hangup_cause_ct) + { + $sip_hangup_cause_string .= "$sip_hangup_cause[$i]|"; + $i++; + } + +$sip_hangup_causes_string='|'; + +$i=0; +$sip_hangup_cause_SQL=""; +while($i < $sip_hangup_cause_ct) + { + if ( (strlen($sip_hangup_cause[$i]) > 0) and (preg_match("/\|$sip_hangup_cause[$i]\|/",$sip_hangup_cause_string)) ) + { + $sip_hangup_causes_string .= "$sip_hangup_cause[$i]|"; + $sip_hangup_causeQS .= "&sip_hangup_cause[]=$sip_hangup_cause[$i]"; + $sip_hangup_cause_SQL.="$sip_hangup_cause[$i],"; + } + $i++; + } + +if ( (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string) ) or ($sip_hangup_cause_ct < 1) ) + { + $HC_rpt_string="- "._QXZ("ALL SIP hangup causes")." "; + if (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string)) + { + $sip_hangup_causeQS="&sip_hangup_cause[]=--ALL--"; + $sip_hangup_cause_SQL=""; + } + } +else + { + $sip_hangup_causes_string=preg_replace('/\!/', "-", $sip_hangup_causes_string); + $HC_rpt_string=_QXZ("AND SIP hangup cause(s)")." ".preg_replace('/\|/', ", ", substr($sip_hangup_causes_string, 1, -1)); + } +$sip_hangup_cause_SQL = preg_replace('/,$/i', '',$sip_hangup_cause_SQL); +if (strlen($sip_hangup_cause_SQL)>0) {$sip_hangup_cause_SQL="and sip_hangup_cause in ($sip_hangup_cause_SQL)";} + +require("screen_colors.php"); + +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.=""._QXZ("$report_name")."\n"; + +$short_header=1; + +$MAIN.="
"; +$MAIN.="\n"; +$MAIN.=""; + +$MAIN.=""; + +$MAIN.="
\n"; +$MAIN.="\n"; +$MAIN.=_QXZ("Date").":\n"; +$MAIN.=""; +$MAIN.="\n"; + +$MAIN.="

"; + +$MAIN.="
"._QXZ("to")."
"; + +$MAIN.="
"._QXZ("Server IP").":
\n"; +$MAIN.="
"._QXZ("SIP Response").":
"; +$MAIN.=""; +$MAIN.="
\n"; +$MAIN.=_QXZ("Display as:")."
"; +$MAIN.="

\n"; + +if ($archives_available=="Y") + { + $MAIN.=""._QXZ("Search archived data")."

\n"; + } + +$MAIN.="

\n"; +$MAIN.="
\n"; +$TEXT.="
\n";
+
+if ($SUBMIT && $query_date) {
+	$stmt="SELECT * From ".$vicidial_dial_log_table." where call_date>='$query_date $query_date_D' and call_date<='$query_date $query_date_T' $server_ip_SQL $sip_hangup_cause_SQL order by call_date asc";
+	$rslt=mysql_to_mysqli($stmt, $link);
+
+	if (!$lower_limit) {$lower_limit=1;}
+	if ($lower_limit+999>=mysqli_num_rows($rslt)) {$upper_limit=($lower_limit+mysqli_num_rows($rslt)%1000)-1;} else {$upper_limit=$lower_limit+999;}
+	$TEXT.="--- "._QXZ("DIAL LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string\n --- "._QXZ("RECORDS")." #$lower_limit-$upper_limit               ["._QXZ("DOWNLOAD")."]\n";
+	$CSV_text="\""._QXZ("CALLER CODE")."\",\""._QXZ("LEAD ID")."\",\""._QXZ("SERVER IP")."\",\""._QXZ("CALL DATE")."\",\""._QXZ("EXTENSION")."\",\""._QXZ("CHANNEL")."\",\""._QXZ("CONTEXT")."\",\""._QXZ("TIMEOUT")."\",\""._QXZ("OUTBOUND CID")."\",\""._QXZ("SIP HANGUP CAUSE")."\",\""._QXZ("UNIQUE ID")."\",\""._QXZ("SIP HANGUP REASON")."\"\n";
+
+	$HTML.="
"; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + + $dial_log_rpt ="+----------------------+-----------+-----------------+---------------------+----------------------+----------------------------------------------------+----------------------+---------+------------------------------------------+--------+----------------------+----------------------------------------------------+\n"; + $dial_log_rpt.="| | | | | | | | | | "._QXZ("SIP",6)." | | |\n"; + $dial_log_rpt.="| | | | | | | | | | "._QXZ("HANGUP",6)." | | |\n"; + $dial_log_rpt.="| "._QXZ("CALLER CODE",20)." | "._QXZ("LEAD ID",9)." | "._QXZ("SERVER IP",15)." | "._QXZ("CALL DATE",19)." | "._QXZ("EXTENSION",20)." | "._QXZ("CHANNEL",50)." | "._QXZ("CONTEXT",20)." | "._QXZ("TIMEOUT",7)." | "._QXZ("OUTBOUND CID",40)." | "._QXZ("CAUSE",6)." | "._QXZ("UNIQUE ID",20)." | "._QXZ("SIP HANGUP REASON",50)." |\n"; + $dial_log_rpt.="+----------------------+-----------+-----------------+---------------------+----------------------+----------------------------------------------------+----------------------+---------+------------------------------------------+--------+----------------------+----------------------------------------------------+\n"; + if ($DB) {$dial_log_rpt.=$stmt."\n";} + + if(mysqli_num_rows($rslt)>0) { + $i=0; + while($row=mysqli_fetch_array($rslt)) { + $i++; + if (strlen($row["extension"])>20) {$row["extension"]=substr($row["extension"], 0, 17)."...";} + if (strlen($row["caller_code"])>20) {$row["caller_code"]=substr($row["caller_code"], 0, 17)."...";} + if (strlen($row["context"])>20) {$row["context"]=substr($row["context"], 0, 17)."...";} + if (strlen($row["outbound_cid"])>40) {$row["outbound_cid"]=substr($row["outbound_cid"], 0, 37)."...";} + if ($i>=$lower_limit && $i<=$upper_limit) { + if (strlen($row["channel"])>50) { + $dial_log_rpt.="| "; + $dial_log_rpt.=sprintf("%-20s",substr($row["caller_code"], 0, 20))." | "; + $dial_log_rpt.=sprintf("%-9s",$row["lead_id"])." | "; + $dial_log_rpt.=sprintf("%-15s",$row["server_ip"])." | "; + $dial_log_rpt.=sprintf("%-19s",$row["call_date"])." | "; + $dial_log_rpt.=sprintf("%-20s", substr($row["extension"], 0, 20))." | "; + $dial_log_rpt.=sprintf("%-50s", substr($row["channel"], 0, 50))." | "; + $dial_log_rpt.=sprintf("%-20s", substr($row["context"], 0, 20))." | "; + $dial_log_rpt.=sprintf("%-7s",$row["timeout"])." | "; + $dial_log_rpt.=sprintf("%-40s", substr($row["outbound_cid"], 0, 40))." | "; + $dial_log_rpt.=sprintf("%-6s",$row["sip_hangup_cause"])." | "; + $dial_log_rpt.=sprintf("%-20s",$row["uniqueid"])." | "; + $dial_log_rpt.=sprintf("%-50s",$row["sip_hangup_reason"])." |\n"; + + $dial_log_rpt.="| "; + $dial_log_rpt.=sprintf("%-20s","")." | "; + $dial_log_rpt.=sprintf("%-9s","")." | "; + $dial_log_rpt.=sprintf("%-15s","")." | "; + $dial_log_rpt.=sprintf("%-19s","")." | "; + $dial_log_rpt.=sprintf("%-20s", "")." | "; + $dial_log_rpt.=sprintf("%-50s", substr($row["channel"], 50))." | "; + $dial_log_rpt.=sprintf("%-20s", "")." | "; + $dial_log_rpt.=sprintf("%-7s","")." | "; + $dial_log_rpt.=sprintf("%-40s", "")." | "; + $dial_log_rpt.=sprintf("%-6s","")." | "; + $dial_log_rpt.=sprintf("%-20s","")." | "; + $dial_log_rpt.=sprintf("%-50s","")." |\n"; + } else { + $dial_log_rpt.="| "; + $dial_log_rpt.=sprintf("%-20s",substr($row["caller_code"], 0, 20))." | "; + $dial_log_rpt.=sprintf("%-9s",$row["lead_id"])." | "; + $dial_log_rpt.=sprintf("%-15s",$row["server_ip"])." | "; + $dial_log_rpt.=sprintf("%-19s",$row["call_date"])." | "; + $dial_log_rpt.=sprintf("%-20s", substr($row["extension"], 0, 20))." | "; + $dial_log_rpt.=sprintf("%-50s", substr($row["channel"], 0, 50))." | "; + $dial_log_rpt.=sprintf("%-20s", substr($row["context"], 0, 20))." | "; + $dial_log_rpt.=sprintf("%-7s",$row["timeout"])." | "; + $dial_log_rpt.=sprintf("%-40s", substr($row["outbound_cid"], 0, 40))." | "; + $dial_log_rpt.=sprintf("%-6s",$row["sip_hangup_cause"])." | "; + $dial_log_rpt.=sprintf("%-20s",$row["uniqueid"])." | "; + $dial_log_rpt.=sprintf("%-50s",$row["sip_hangup_reason"])." |\n"; + } + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + } + $CSV_text.="\"$row[caller_code]\",\"$row[lead_id]\",\"$row[server_ip]\",\"$row[call_date]\",\"$row[extension]\",\"$row[channel]\",\"$row[context]\",\"$row[timeout]\",\"$row[outbound_cid]\",\"$row[sip_hangup_cause]\",\"$row[uniqueid]\",\"$row[sip_hangup_reason]\"\n"; + } + } else { + $dial_log_rpt.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; + $HTML.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; + } + $dial_log_rpt.="+----------------------+-----------+-----------------+---------------------+----------------------+----------------------------------------------------+----------------------+---------+------------------------------------------+--------+----------------------+----------------------------------------------------+\n"; + + $dial_log_rpt_hf=""; + $ll=$lower_limit-1000; + $HTML.=""; + if ($ll>=1) { + $dial_log_rpt_hf.="[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."]"; + $HTML.=""; + } else { + $dial_log_rpt_hf.=sprintf("%-23s", " "); + $HTML.="
"._QXZ("DIAL LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string, "._QXZ("RECORDS")." #$lower_limit-$upper_limit["._QXZ("DOWNLOAD")."]
"._QXZ("CALLER CODE").""._QXZ("LEAD ID").""._QXZ("SERVER IP").""._QXZ("CALL DATE").""._QXZ("EXTENSION").""._QXZ("CHANNEL").""._QXZ("CONTEXT").""._QXZ("TIMEOUT").""._QXZ("OUTBOUND CID").""._QXZ("SIP HANGUP CAUSE").""._QXZ("UNIQUE ID").""._QXZ("SIP HANGUP REASON")."
".$row["caller_code"]."".$row["lead_id"]."".$row["server_ip"]."".$row["call_date"]."".$row["extension"]."".$row["channel"]."".$row["context"]."".$row["timeout"]."".$row["outbound_cid"]."".$row["sip_hangup_cause"]."".$row["uniqueid"]."".$row["sip_hangup_reason"]."
[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."] "; + } + $dial_log_rpt_hf.=sprintf("%-145s", " "); + + if (($lower_limit+1000)=mysqli_num_rows($rslt)) {$max_limit=mysqli_num_rows($rslt)-$upper_limit;} else {$max_limit=1000;} + $dial_log_rpt_hf.="["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; + $HTML.="["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; + } else { + $dial_log_rpt_hf.=sprintf("%23s", " "); + $HTML.=" "; + } + $dial_log_rpt_hf.="\n"; + $TEXT.=$dial_log_rpt_hf.$dial_log_rpt.$dial_log_rpt_hf; + + $TEXT.="\n"; + $HTML.="
"; + + if ($report_display_type=="HTML") { + $MAIN.=$HTML; + } else { + $MAIN.=$TEXT; + } +} + if ($file_download>0) { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_dial_log_report_$US$FILE_TIME.csv"; + $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); + $CSV_text=preg_replace('/\" +/', '"', $CSV_text); + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + + } else { + echo $HEADER; + require("admin_header.php"); + echo $MAIN; + } + +$endMS = microtime(); +$startMSary = explode(" ",$startMS); +$endMSary = explode(" ",$endMS); +$runS = ($endMSary[0] - $startMSary[0]); +$runM = ($endMSary[1] - $startMSary[1]); +$TOTALrun = ($runS + $runM); + +$END_TIME=date("U"); + +#print "Total run time: ".($END_TIME-$START_TIME); + +$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); + +?> diff --git a/agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php b/agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php index f0809213..488834e6 100644 --- a/agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php +++ b/agc_2-X/trunk/www/vicidial/AST_dialer_inventory_report.php @@ -1,1058 +1,1060 @@ - LICENSE: AGPLv2 -# Matt Florell -# -# NOTES: -# - For snapshots, the AST_dialer_inventory_snapshot.pl script should be put in -# the crontab and run on a nightly basis after-hours -# -# -# CHANGES -# 111013-0054 - First build -# 111106-1327 - Reformatting, other minor changes -# 111230-1145 - Debugging additions and more minor changes -# 120221-2237 - Added totals, list options, other small changes -# 130414-0131 - Added report logging -# 130610-1021 - Finalized changing of all ereg instances to preg -# 130621-0800 - Added filtering of input to prevent SQL injection attacks and new user auth -# 130902-0735 - Changed to mysqli PHP functions -# 140108-0743 - Added webserver and hostname to report logging -# 140328-0005 - Converted division calculations to use MathZDC function -# 141114-0006 - Finalized adding QXZ translation to all admin files -# 141230-1509 - Added code for on-the-fly language translations display -# 160227-1933 - Uniform form format -# 170409-1538 - Added IP List validation code -# 170829-0040 - Added screen color settings -# 191013-0845 - Fixes for PHP7 -# - -$startMS = microtime(); - -error_reporting(0); - -require("dbconnect_mysqli.php"); -require("functions.php"); - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["group"])) {$group=$_GET["group"];} - elseif (isset($_POST["group"])) {$group=$_POST["group"];} -if (isset($_GET["report_type"])) {$report_type=$_GET["report_type"];} - elseif (isset($_POST["report_type"])) {$report_type=$_POST["report_type"];} -if (isset($_GET["selected_list"])) {$selected_list=$_GET["selected_list"];} - elseif (isset($_POST["selected_list"])) {$selected_list=$_POST["selected_list"];} -if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} -if (isset($_GET["time_setting"])) {$time_setting=$_GET["time_setting"];} - elseif (isset($_POST["time_setting"])) {$time_setting=$_POST["time_setting"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["report_source"])) {$report_source=$_GET["report_source"];} - elseif (isset($_POST["report_source"])) {$report_source=$_POST["report_source"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["DBX"])) {$DBX=$_GET["DBX"];} - elseif (isset($_POST["DBX"])) {$DBX=$_POST["DBX"];} -if (isset($_GET["snapshot_time"])) {$snapshot_time=$_GET["snapshot_time"];} - elseif (isset($_POST["snapshot_time"])) {$snapshot_time=$_POST["snapshot_time"];} -if (isset($_GET["override_24hours"])) {$override_24hours=$_GET["override_24hours"];} - elseif (isset($_POST["override_24hours"])) {$override_24hours=$_POST["override_24hours"];} - -$MT[0]=''; -$NOW_DATE = date("Y-m-d"); -$NOW_TIME = date("Y-m-d H:i:s"); -$time_start = microtime(true); -$STARTtime = date("U"); -if (!isset($group)) {$group = array();} -if (!isset($query_date)) {$query_date = $NOW_DATE;} -if (!isset($end_date)) {$end_date = $NOW_DATE;} - - -$report_name = 'Dialer Inventory Report'; -$db_source = 'M'; - -############################################# -##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method FROM system_settings;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_header.="$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $non_latin = $row[0]; - $outbound_autodial_active = $row[1]; - $slave_db_server = $row[2]; - $reports_use_slave_db = $row[3]; - $SSenable_languages = $row[4]; - $SSlanguage_method = $row[5]; - } -##### END SETTINGS LOOKUP ##### -########################################### - -if ($non_latin < 1) - { - $PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER); - $PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW); - } -else - { - $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); - $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); - } - -$stmt="SELECT selected_language from vicidial_users where user='$PHP_AUTH_USER';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$sl_ct = mysqli_num_rows($rslt); -if ($sl_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $VUselected_language = $row[0]; - } - -$auth=0; -$reports_auth=0; -$admin_auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth > 0) - { - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $admin_auth=$row[0]; - - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $reports_auth=$row[0]; - - if ($reports_auth < 1) - { - $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ( ($reports_auth > 0) and ($admin_auth < 1) ) - { - $ADD=999999; - $reports_only_user=1; - } - } -else - { - $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ($auth_message == 'IPBLOCK') - { - $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - -##### BEGIN log visit to the vicidial_report_log table ##### -$LOGip = getenv("REMOTE_ADDR"); -$LOGbrowser = getenv("HTTP_USER_AGENT"); -$LOGscript_name = getenv("SCRIPT_NAME"); -$LOGserver_name = getenv("SERVER_NAME"); -$LOGserver_port = getenv("SERVER_PORT"); -$LOGrequest_uri = getenv("REQUEST_URI"); -$LOGhttp_referer = getenv("HTTP_REFERER"); -$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); -$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); -$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); -if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} -else {$LOGserver_port = ":$LOGserver_port";} -$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; - -$LOGhostname = php_uname('n'); -if (strlen($LOGhostname)<1) {$LOGhostname='X';} -if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} - -$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$webserver_id_ct = mysqli_num_rows($rslt); -if ($webserver_id_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $webserver_id = $row[0]; - } -else - { - ##### insert webserver entry - $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $affected_rows = mysqli_affected_rows($link); - $webserver_id = mysqli_insert_id($link); - } - -$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$report_log_id = mysqli_insert_id($link); -##### END log visit to the vicidial_report_log table ##### - -if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) - { - mysqli_close($link); - $use_slave_server=1; - $db_source = 'S'; - require("dbconnect_mysqli.php"); - #$HTML_header.="\n"; - } - -$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; -if ($DB) {$HTML_header.="|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGuser_group = $row[0]; - -$stmt="SELECT allowed_campaigns,allowed_reports from vicidial_user_groups where user_group='$LOGuser_group';"; -if ($DB) {$HTML_header.="|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGallowed_campaigns = $row[0]; -$LOGallowed_reports = $row[1]; - -if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) - { - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; - exit; - } - -$inventory_allow_realtime = 0; -if (file_exists('options.php')) - { - require('options.php'); - } - -$LOGallowed_campaignsSQL=''; -$whereLOGallowed_campaignsSQL=''; -if ( (!preg_match('/\-ALL/i', $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')"; - } -$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - $group_string .= "$group[$i]|"; - $i++; - } - -$stmt="SELECT campaign_id from vicidial_campaigns where campaign_id in (SELECT distinct campaign_id from vicidial_lists where inventory_report='Y') $LOGallowed_campaignsSQL order by campaign_id;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) { echo "$stmt\n";} -$campaigns_to_print = mysqli_num_rows($rslt); -$i=0; -$groups=array(); -while ($i < $campaigns_to_print) - { - $row=mysqli_fetch_row($rslt); - $groups[$i] =$row[0]; - if (preg_match('/\-ALL/',$group_string) ) - {$group[$i] = $groups[$i];} - $i++; - } - - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) - { - $group_string .= "$group[$i]|"; - $group_SQL .= "'$group[$i]',"; - $groupQS .= "&group[]=$group[$i]"; - } - $i++; - } - -if ( (preg_match('/\-\-ALL\-\-/',$group_string) ) or ($group_ct < 1) ) - {$group_SQL = "";} -else - { - $group_SQL = preg_replace('/,$/i', '',$group_SQL); - $group_SQL = "and campaign_id IN($group_SQL)"; - } - -$stmt="SELECT list_id, list_name from vicidial_lists where inventory_report='Y' $LOGallowed_campaignsSQL order by list_id, list_name;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_header.="$stmt\n";} -$lists_to_print = mysqli_num_rows($rslt); -$i=0; -$lists=array(); -$list_names=array(); -while ($i < $lists_to_print) - { - $row=mysqli_fetch_row($rslt); - $lists[$i] = $row[0]; - $list_names[$i] = $row[1]; - $i++; - } - -$campaign_span_txt=_QXZ("Campaigns").":
"; -$campaign_span_txt.=""; - -$list_span_txt=_QXZ("Lists").":
"; -$list_span_txt.=""; - -$snapshot_span_txt=_QXZ("Snapshot time").":
"; -$snapshot_stmt="SELECT distinct snapshot_time from dialable_inventory_snapshots order by snapshot_time desc limit 100;"; -if ($DBX > 0) {$HTML_header.= "|$snapshot_stmt|\n";} -$snapshot_rslt=mysql_to_mysqli($snapshot_stmt, $link); -$snapshot_span_txt.="\n"; - -require("screen_colors.php"); - -$NWB = "   \"HELP\""; - -$HTML_header.="\n"; -$HTML_header.="\n"; -$HTML_header.="\n"; - -if ($report_type=='LIST') {$onload="onload=\"ToggleSpan('list_span', 'campaign_span')\"";} - -$HTML_header.="\n"; -$HTML_header.="\n"; -$HTML_header.="\n"; -$HTML_header.=""._QXZ("$report_name")."\n"; -$HTML_header.="
\n";
-
-$rpt_header="";
-####### STAT GENERATION #######
-require("count_functions.inc");
-function GetListCount($list_id, $inventory_ptnstr) 
-	{
-	global $list_start_inv;
-	global $new_count;
-	global $link;
-	global $total_calls;
-	$ct_stmt="SELECT status, called_count, count(*) From vicidial_list where list_id='$list_id' group by status, called_count order by status, called_count;";
-	if ($DBX > 0) {$HTML_header.= "|$ct_stmt|\n";}
-	$ct_rslt=mysql_to_mysqli($ct_stmt, $link);
-	$new_count=0; $total_calls=0;
-	while ($ct_row=mysqli_fetch_row($ct_rslt)) 
-		{
-		$list_start_inv+=$ct_row[2];
-		$total_calls+=($ct_row[1]*$ct_row[2]);
-		if (preg_match('/|$ct_row[0]|/', $inventory_ptnstr) && $ct_row[1]=="0") {$new_count+=$ct_row[2];} 
-		}
-	}
-
-if ($SUBMIT) 
-	{
-
-	$total_list_start_inv=0;
-	$total_dialable_count=0;
-	$total_dialable_count_nofilter=0;
-	$total_dialable_count_oneoff=0;
-	$total_dialable_count_inactive=0;
-	$total_total_calls=0;
-	$total_average_call_count=0;
-	$total_penetration=0;
-
-	$shift_ary=array();
-	if ($snapshot_time && $report_source=="SNAPSHOT") 
-		{
-		$rpt_header=_QXZ("SNAPSHOT from")." $snapshot_time\n";
-		$stmt="SELECT distinct shift_data from dialable_inventory_snapshots where snapshot_time='$snapshot_time' and time_setting='$time_setting' $time_clause order by campaign_id, list_id;";
-		if ($DBX > 0) {$HTML_header.= "|$stmt|\n";}
-		$rslt=mysql_to_mysqli($stmt, $link);
-		$shift_SQL_str="";
-		while ($shift_row=mysqli_fetch_array($rslt)) 
-			{
-			$shift_data1=explode("|", $shift_row["shift_data"]);
-			for ($i=0; $i 0) {$HTML_header.= "|$shift_stmt|\n";}
-		$shift_rslt=mysql_to_mysqli($shift_stmt, $link);
-		$c=0;
-		while($shift_row=mysqli_fetch_array($shift_rslt)) 
-			{
-			$rpt_header_SHIFTS.=" ".sprintf("%8s", substr($shift_row["shift_id"],0,8))." |";
-			$CSV_header_SHIFTS.="\"$shift_row[shift_id]\",";
-			$rpt_header_SHIFTS_lower.="          |";
-			$rpt_header_BORDER.="----------+";
-			$shift_ary[$c]=$shift_row["shift_id"];
-			$total_varname="total_".$shift_row["shift_id"];
-			$$total_varname=0;
-			if ($DB > 0) {echo "
-$c-$shift_ary[$c]-$shift_row[shift_id]-\n";} - $c++; - } - - if ($report_type=="CAMPAIGNS") {$time_clause=$group_SQL;} - if ($report_type=="LIST") {$time_clause="and list_id='$selected_list'";} - $stmt="SELECT snapshot_id,snapshot_time,list_id,list_name,list_description,campaign_id,list_lastcalldate,list_start_inv,dialable_count,dialable_count_nofilter,dialable_count_oneoff,dialable_count_inactive,average_call_count,penetration,shift_data,time_setting from dialable_inventory_snapshots where snapshot_time='$snapshot_time' and time_setting='$time_setting' $time_clause order by campaign_id, list_id;"; - if ($DBX > 0) {$HTML_header.= "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - while ($row=mysqli_fetch_array($rslt)) - { - $row["list_description"]=substr($row["list_description"], 0, 30); - if (strlen($row["list_description"])>0) {$list_info=$row["list_description"];} else {$list_info=$row["list_name"];} - $rpt_body.="| ".sprintf("%9s", $row["list_id"])." | ".sprintf("%-30s", $list_info)." | ".sprintf("%8s", $row["campaign_id"])." | ".$row["list_lastcalldate"]." | ".sprintf("%9s", $row["list_start_inv"])." | ".sprintf("%8s", $row["dialable_count"])." | ".sprintf("%8s", $row["dialable_count_nofilter"])." | ".sprintf("%8s", $row["dialable_count_oneoff"])." | ".sprintf("%8s", $row["dialable_count_inactive"])." | ".sprintf("%8s", $row["average_call_count"])." | ".sprintf("%6s", $row["penetration"])."% |"; - $CSV_body.="\"$row[list_id]\",\"$list_info\",\"$row[last_calldate]\",\"$row[campaign_id]\",\"$row[list_start_inv]\",\"$row[dialable_count]\",\"$row[dialable_count_nofilter]\",\"$row[dialable_count_oneoff]\",\"$row[dialable_count_inactive]\",\"$row[average_call_count]\",\"$row[penetration] %\""; - - $total_list_start_inv+=$row["list_start_inv"]; - $total_dialable_count+=$row["dialable_count"]; - $total_dialable_count_nofilter+=$row["dialable_count_nofilter"]; - $total_dialable_count_oneoff+=$row["dialable_count_oneoff"]; - $total_dialable_count_inactive+=$row["dialable_count_inactive"]; - $total_total_calls+=($row["average_call_count"]*$row["list_start_inv"]); - - $shift_data_a=explode("|", $row["shift_data"]); - $b=0; - while ($b < count($shift_ary)) - { - $a=0; - $no_match=0; - while ($a < count($shift_data_a)) - { - $shift_data_b=explode(",", $shift_data_a[$a]); - $line_match=0; - if ($shift_ary[$b] == "$shift_data_b[0]") - { - $rpt_body.=" ".sprintf("%8s", $shift_data_b[1])." |"; - $CSV_body.=",\"$shift_data_b[1]\""; - $total_varname="total_".$shift_data_b[0]; - $$total_varname+=$shift_data_b[1]; - $line_match++; - $no_match++; - } - if ($DB > 0) {echo "
-$a-$b-$shift_ary[$b]-$shift_data_b[0]($shift_data_b[1])-$line_match-\n";} - $a++; - } - if ($no_match==0) - { - $rpt_body.=" ".sprintf("%8s", "0")." |"; - $CSV_body.=",\"0\""; - } - $b++; - } - $rpt_body.="\n"; - $CSV_body.="\n"; - } - } - else - { - $single_status=1; - - ## If time setting is set to 'Local', compile a list of time zone offsets and make an array of those offsets with the amount of time that needs to be added or subtracted - if ($time_setting=="LOCAL") - { - $gmt_stmt="SELECT default_local_gmt from system_settings;"; - $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); - $gmt_row=mysqli_fetch_row($gmt_rslt); - $local_offset=$gmt_row[0]; - - if ($report_type=="CAMPAIGNS") {$time_clause="where list_id in (SELECT list_id from vicidial_lists where inventory_report='Y' ".substr($group_SQL,4).")";} - if ($report_type=="LIST") {$time_clause="where list_id='$selected_list'";} - $gmt_stmt="SELECT distinct gmt_offset_now, gmt_offset_now-($local_offset) from vicidial_list $time_clause ;"; - if ($DB) {$HTML_header.=$gmt_stmt."
\n";} - $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); - while ($gmt_row=mysqli_fetch_row($gmt_rslt)) - { - $gmt_row[1]=preg_replace('/25$/', '15', $gmt_row[1]); - $gmt_row[1]=preg_replace('/75$/', '45', $gmt_row[1]); - $gmt_row[1]=preg_replace('/\.5$/', '.30', $gmt_row[1]); - $gmt_row[1]=preg_replace('/\./', ':', $gmt_row[1]); - $gri = $gmt_row[0]; - $gmt_array[$gri]=$gmt_row[1]; - } - } - - # Get shift information - $shift_stmt="SELECT shift_id, shift_name, str_to_date(shift_start_time, '%H%i') as shift_start_time, addtime(str_to_date(shift_start_time, '%H%i'), shift_length) as shift_end_time, if(addtime(str_to_date(shift_start_time, '%H%i'), shift_length)>'23:59:59', '1', '0') as day_offset, shift_weekdays from vicidial_shifts where report_option='Y' order by report_rank, shift_start_time asc;"; - if ($DB) {$HTML_header.="$shift_stmt;\n";} - $shift_rslt=mysql_to_mysqli($shift_stmt, $link); - while($shift_row=mysqli_fetch_array($shift_rslt)) - { - $rpt_header_SHIFTS.=" ".sprintf("%8s", substr($shift_row["shift_id"],0,8))." |"; - $rpt_header_SHIFTS_lower.=" |"; - $CSV_header_SHIFTS.="\"$shift_row[shift_id]\","; - $rpt_header_BORDER.="----------+"; - $shift_ary[$shift_row["shift_id"]][0]=$shift_row["shift_name"]; - $shift_ary[$shift_row["shift_id"]][1]=$shift_row["shift_start_time"]; - $shift_ary[$shift_row["shift_id"]][2]=$shift_row["shift_end_time"]; - $shift_ary[$shift_row["shift_id"]][3]=$shift_row["day_offset"]; - $shift_ary[$shift_row["shift_id"]][4]=$shift_row["shift_weekdays"]; - } - - $rpt_body=""; - if ($group_ct>0 && $report_type=="CAMPAIGNS") - { - for ($i=0; $i<$group_ct; $i++) - { - $campaign_stmt="SELECT call_count_limit, call_count_target, dial_statuses, local_call_time, drop_lockout_time from vicidial_campaigns where campaign_id='$group[$i]' $LOGallowed_campaignsSQL;"; - if ($DB) {$HTML_header.="$campaign_stmt;\n";} - $campaign_rslt=mysql_to_mysqli($campaign_stmt, $link); - $campaign_row=mysqli_fetch_row($campaign_rslt); - $call_count_limit=$campaign_row[0]; - $call_count_target=$campaign_row[1]; - $active_dial_statuses=$campaign_row[2]; - $local_call_time=$campaign_row[3]; if ($override_24hours) {$local_call_time="24hours";} - $drop_lockout_time=$campaign_row[4]; - - $stmt="SELECT distinct status from vicidial_statuses where completed='N' UNION SELECT distinct status from vicidial_campaign_statuses where completed='N' and campaign_id='$group[$i]' $LOGallowed_campaignsSQL"; - if ($DB) {$HTML_header.="$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $dial_statuses=" "; - $inventory_statuses=" "; - $inventory_ptnstr="|"; - $inactive_dial_statuses=" "; - while ($row=mysqli_fetch_row($rslt)) - { - $dial_statuses.="$row[0] "; - $inventory_statuses.="'$row[0]',"; - $inventory_ptnstr.="$row[0]|"; - if (!preg_match("/ $row[0] /", "$active_dial_statuses")) {$inactive_dial_statuses.="$row[0] ";} - } - $inventory_statuses=substr($inventory_statuses, 0, -1); - if ($DB) {$HTML_header.= " "._QXZ("CAMPAIGN DIAL STATUSES",30,"r").": |$active_dial_statuses|\n";} - if ($DB) {$HTML_header.= " "._QXZ("INVENTORY STATUSES RESULTS",30,"r").": |$inventory_statuses|\n";} - if ($DB) {$HTML_header.= " "._QXZ("INACTIVE STATUSES RESULTS",30,"r").": |$inactive_dial_statuses|\n";} - - $filter_stmt="SELECT lead_filter_sql from vicidial_campaigns v, vicidial_lead_filters vlf where v.campaign_id='$group[$i]' and v.lead_filter_id=vlf.lead_filter_id limit 1;"; - if ($DB) {$HTML_header.="$filter_stmt;\n";} - $filter_rslt=mysql_to_mysqli($filter_stmt, $link); - $filter_row=mysqli_fetch_row($filter_rslt); - if (strlen($filter_row[0])>0) {$filter_SQL=" and $filter_row[0]";} else {$filter_SQL="";} - $filter_SQL = preg_replace("/\\\/",'',$filter_SQL); - - $lists_stmt="SELECT list_id, list_name, list_description, if(list_lastcalldate is null, '*** Not called *** ', list_lastcalldate) as list_lastcalldate from vicidial_lists where campaign_id='$group[$i]' and inventory_report='Y' $LOGallowed_campaignsSQL order by list_id asc;"; - if ($DB) {$HTML_header.="$lists_stmt;\n";} - $lists_rslt=mysql_to_mysqli($lists_stmt, $link); - while ($lists_row=mysqli_fetch_array($lists_rslt)) - { - $list_id=$lists_row["list_id"]; - $list_name=$lists_row["list_name"]; - $lists_row["list_description"]=substr($lists_row["list_description"], 0, 30); - $list_description=$lists_row["list_description"]; - $last_calldate=$lists_row["list_lastcalldate"]; - if (strlen($list_description)>0) {$list_info=$list_description;} else {$list_info=$list_name;} - - $list_start_inv=0; - GetListCount($list_id, $inventory_ptnstr); - $average_calls=sprintf("%.1f", MathZDC($total_calls, $list_start_inv)); - $Xdialable_count_nofilter = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,""); - if (strlen($inactive_dial_statuses)>1) - { - $Xdialable_inactive_count = dialable_leads($DB,$link,$local_call_time,"$inactive_dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL"); - } - else - { - $Xdialable_inactive_count = 0; - } - - $oneoff_SQL=$filter_SQL." and (called_count < $call_count_limit-1) "; - $oneoff_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$oneoff_SQL"); - - $full_dialable_SQL=""; - $Xdialable_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL"); - - $penetration=sprintf("%.2f", (MathZDC(100*($list_start_inv-$Xdialable_count), $list_start_inv))); - - $rpt_body.="| ".sprintf("%9s", $list_id)." | ".sprintf("%-30s", $list_info)." | ".sprintf("%8s", $group[$i])." | ".$last_calldate." | ".sprintf("%9s", $list_start_inv)." | ".sprintf("%8s", $Xdialable_count)." | ".sprintf("%8s", $Xdialable_count_nofilter)." | ".sprintf("%8s", $oneoff_count)." | ".sprintf("%8s", $Xdialable_inactive_count)." | ".sprintf("%8s", $average_calls)." | ".sprintf("%6s", $penetration)."% |"; - $CSV_body.="\"$list_id\",\"$list_info\",\"$last_calldate\",\"$group[$i]\",\"$list_start_inv\",\"$Xdialable_count\",\"$Xdialable_count_nofilter\",\"$oneoff_count\",\"$Xdialable_inactive_count\",\"$average_calls\",\"$penetration %\""; - - $total_list_start_inv+=$list_start_inv; - $total_dialable_count+=$Xdialable_count; - $total_dialable_count_nofilter+=$Xdialable_count_nofilter; - $total_dialable_count_oneoff+=$oneoff_count; - $total_dialable_count_inactive+=$Xdialable_inactive_count; - $total_total_calls+=$total_calls; - - # $stat_stmt="SELECT call_date, dayofweek(call_date) from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where list_id='$list_id' and called_count<='$called_count_limit' and status in ($inventory_statuses) $filter_SQL"; - # SELECT lead_id, count(*) as count from vicidial_log where extract(HOUR_MINUTE FROM call_date)>='900' and extract(HOUR_MINUTE FROM call_date)<='1700' and dayofweek(call_date) in (2,3,4,5,6) and lead_id in (SELECT lead_id from vicidial_list where list_id=41073) group by lead_id order by lead_id; - - $shift_ary2=$shift_ary; -# while (list($key, $val)=each($shift_ary2)) - foreach ($shift_ary2 as $key => $val) - { - $total_shift_count=0; - $gmt_stmt="SELECT distinct gmt_offset_now from vicidial_list where list_id='$list_id';"; - if ($DB) {$HTML_header.="$gmt_stmt\n";} - $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); - while ($gmt_row=mysqli_fetch_row($gmt_rslt)) - { - if ($time_setting=="LOCAL") - { - $gri = $gmt_row[0]; - $offset_hours=$gmt_array[$gri]; - } - else - { - $offset_hours=0; - } - - if (strlen($val[4])>0) - { - if ($val[3]==0) - { - $shift_days_SQL=" and time(addtime(call_date, '$offset_hours'))>='$val[1]' and time(addtime(call_date, '$offset_hours'))<='$val[2]' "; - $day_str=""; - for ($j=0; $j=addtime('09:00', '00:04:00') - } - $shift_days_SQL=substr($shift_days_SQL, 0, -3).")"; - } - } - else - { - $shift_days_SQL=""; - } - - $shift_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target';"; - - $shift_rslt=mysql_to_mysqli($shift_stmt, $link); - $shift_row=mysqli_fetch_row($shift_rslt); - if ($DB) {$HTML_header.="$shift_stmt
$shift_row[0]
\n";} - $total_shift_count+=$shift_row[0]; - } - $shift_count=$Xdialable_count-$total_shift_count; - $rpt_body.=" ".sprintf("%8s", $shift_count)." |"; - $total_varname="total_".$key; - $$total_varname+=$shift_count; - $CSV_body.=",\"$shift_count\""; - } - $rpt_body.="\n"; - $CSV_body.="\n"; - if (!$file_download) {echo $HTML_header; $HTML_header=""; flush();} - } - } - } - else if ($selected_list && $report_type=="LIST") - { - $campaign_stmt="SELECT call_count_limit, call_count_target, dial_statuses, local_call_time, drop_lockout_time, v.campaign_id from vicidial_campaigns v, vicidial_lists vl where inventory_report='Y' and vl.list_id='$selected_list' and vl.campaign_id=v.campaign_id;"; - if ($DB) {$HTML_header.="$campaign_stmt;\n";} - $campaign_rslt=mysql_to_mysqli($campaign_stmt, $link); - $campaign_row=mysqli_fetch_row($campaign_rslt); - $call_count_limit=$campaign_row[0]; - $call_count_target=$campaign_row[1]; - $active_dial_statuses=$campaign_row[2]; - $local_call_time=$campaign_row[3]; if ($override_24hours) {$local_call_time="24hours";} - $drop_lockout_time=$campaign_row[4]; - $campaign_id=$campaign_row[5]; - - $stmt="SELECT distinct status from vicidial_statuses where completed='N' UNION SELECT distinct status from vicidial_campaign_statuses where completed='N' and campaign_id=(SELECT campaign_id from vicidial_lists where list_id='$selected_list' and inventory_report='Y' $LOGallowed_campaignsSQL);"; - if ($DB) {$HTML_header.="$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $inactive_dial_statuses=" "; - $dial_statuses=" "; - $inventory_statuses=""; - $inventory_ptnstr="|"; - while ($row=mysqli_fetch_row($rslt)) - { - $dial_statuses.="$row[0] "; - $inventory_statuses.="'$row[0]',"; - $inventory_ptnstr.="$row[0]|"; - if (!preg_match("/ $row[0] /", "$active_dial_statuses")) {$inactive_dial_statuses.="$row[0] ";} - } - $inventory_statuses=substr($inventory_statuses, 0, -1); - if ($DB) {$HTML_header.= " "._QXZ("CAMPAIGN DIAL STATUSES",30,"r").": |$active_dial_statuses|\n";} - if ($DB) {$HTML_header.= " "._QXZ("DIAL STATUSES",30,"r").": |$dial_statuses|\n";} - if ($DB) {$HTML_header.= " "._QXZ("INVENTORY STATUSES RESULTS",30,"r").": |$inventory_statuses|\n";} - if ($DB) {$HTML_header.= " "._QXZ("INACTIVE STATUSES RESULTS",30,"r").": |$inactive_dial_statuses|\n";} - - if ($DB) {$HTML_header.="$campaign_stmt; - $dial_statuses\n";} - - $filter_stmt="SELECT lead_filter_sql from vicidial_campaigns v, vicidial_lead_filters vlf where v.campaign_id='$campaign_id' and v.lead_filter_id=vlf.lead_filter_id limit 1;"; - if ($DB) {$HTML_header.="$filter_stmt;\n";} - $filter_rslt=mysql_to_mysqli($filter_stmt, $link); - $filter_row=mysqli_fetch_row($filter_rslt); - if (strlen($filter_row[0])>0) {$filter_SQL=" and $filter_row[0]";} else {$filter_SQL="";} - $filter_SQL = preg_replace("/\\\/",'',$filter_SQL); - - $lists_stmt="SELECT list_id, list_name, list_description, if(list_lastcalldate is null, '*** "._QXZ("Not called")." *** ', list_lastcalldate) as list_lastcalldate, campaign_id from vicidial_lists where list_id='$selected_list' and inventory_report='Y' $LOGallowed_campaignsSQL order by list_id asc;"; - if ($DB) {$HTML_header.="$lists_stmt;\n";} - $lists_rslt=mysql_to_mysqli($lists_stmt, $link); - while ($lists_row=mysqli_fetch_array($lists_rslt)) - { - $list_id=$lists_row["list_id"]; - $list_name=$lists_row["list_name"]; - $lists_row["list_description"]=substr($lists_row["list_description"], 0, 30); - $list_description=$lists_row["list_description"]; - $last_calldate=$lists_row["list_lastcalldate"]; - $campaign_id=$lists_row["campaign_id"]; - if (strlen($list_description)>0) {$list_info=$list_description;} else {$list_info=$list_name;} - $list_call_inv=0; - GetListCount($list_id, $inventory_ptnstr); - $average_calls=sprintf("%.1f", MathZDC($total_calls, $list_start_inv)); - - ### For TOTAL counts, needs to be here instead of with other "total" variables further down in this particular report - $total_total_calls+=$total_calls; - - $Xdialable_count_nofilter = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,""); - if (strlen($inactive_dial_statuses)>1) - { - $Xdialable_inactive_count = dialable_leads($DB,$link,$local_call_time,"$inactive_dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL"); - } - else - { - $Xdialable_inactive_count = 0; - } - - $oneoff_SQL=$filter_SQL." and (called_count < $call_count_limit-1) "; - $oneoff_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$oneoff_SQL"); - - $full_dialable_SQL=""; - $Xdialable_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL"); - if ($DB > 0) {echo _QXZ("FULL DIALABLE SQL").": |$full_dialable_SQL|";} - } - - $penetration=sprintf("%.2f", (MathZDC(100*($list_start_inv-$Xdialable_count), $list_start_inv))); - - $rpt_body.="| ".sprintf("%9s", $list_id)." | ".sprintf("%-30s", $list_info)." | ".sprintf("%8s", $campaign_id)." | ".$last_calldate." | ".sprintf("%9s", $list_start_inv)." | ".sprintf("%8s", $Xdialable_count)." | ".sprintf("%8s", $Xdialable_count_nofilter)." | ".sprintf("%8s", $oneoff_count)." | ".sprintf("%8s", $Xdialable_inactive_count)." | ".sprintf("%8s", $average_calls)." | ".sprintf("%6s", $penetration)."% |"; - $CSV_body.="\"$list_id\",\"$list_info\",\"$last_calldate\",\"$campaign_id\",\"$list_start_inv\",\"$Xdialable_count\",\"$Xdialable_count_nofilter\",\"$oneoff_count\",\"$Xdialable_inactive_count\",\"$average_calls\",\"$penetration %\""; - - $total_list_start_inv+=$list_start_inv; - $total_dialable_count+=$Xdialable_count; - $total_dialable_count_nofilter+=$Xdialable_count_nofilter; - $total_dialable_count_oneoff+=$oneoff_count; - $total_dialable_count_inactive+=$Xdialable_inactive_count; - - $shift_ary2=$shift_ary; -# while (list($key, $val)=each($shift_ary2)) - foreach ($shift_ary2 as $key => $val) - { - $total_shift_count=0; - $total_nofilter_shift_count=0; - $total_oneoff_shift_count=0; - $total_undialable_shift_count=0; - $total_nofilter_undialable_shift_count=0; - $gmt_stmt="SELECT distinct gmt_offset_now from vicidial_list where list_id='$list_id';"; - if ($DB) {$HTML_header.="$gmt_stmt\n";} - $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); - while ($gmt_row=mysqli_fetch_row($gmt_rslt)) - { - if ($time_setting=="LOCAL") - { - $gri = $gmt_row[0]; - $offset_hours=$gmt_array[$gri]; - } - else - { - $offset_hours=0; - } - - if (strlen($val[4])>0) - { - if ($val[3]==0) - { - $shift_days_SQL=" and time(addtime(call_date, '$offset_hours'))>='$val[1]' and time(addtime(call_date, '$offset_hours'))<='$val[2]' "; - $day_str=""; - for ($i=0; $i=addtime('09:00', '00:04:00') - } - $shift_days_SQL=substr($shift_days_SQL, 0, -3).")"; - } - } - else - { - $shift_days_SQL=""; - } - -# $dialable_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; -# $dialable_nofilter_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]') $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; -# $undialable_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; -# $undialable_nofilter_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]') $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; -# $oneoff_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='($call_count_target-1)'"; - $shift_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target';"; - - $shift_rslt=mysql_to_mysqli($shift_stmt, $link); - $shift_row=mysqli_fetch_row($shift_rslt); - if ($DB) {$HTML_header.="$shift_stmt;
$shift_row[0]
\n";} - $total_shift_count+=$shift_row[0]; - } - $shift_count=$Xdialable_count-$total_shift_count; - $rpt_body.=" ".sprintf("%8s", $shift_count)." |"; - $total_varname="total_".$key; - $$total_varname+=$shift_count; - $CSV_body.=",\"$shift_count\""; - } - $rpt_body.="\n"; - $CSV_body.="\n"; - if (!$file_download) {echo $HTML_header; $HTML_header=""; flush();} - } - } - - $rpt_header.=_QXZ("Date").": ".date("m/d/Y")." -- "._QXZ("Time").": ".date("H:i a")."\n\n"; - $rpt_header.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; - $rpt_header.="| "._QXZ("Call list",9)." | "._QXZ("List description",30)." | "._QXZ("Campaign",8)." | "._QXZ("Last call date",19)." | "._QXZ("Start Inv",9)." | "._QXZ("Call Inv",8)." | "._QXZ("Call Inv",8)." | "._QXZ("Call Inv",8)." | "._QXZ("Call Inv",8)." | "._QXZ("Dial Avg",8)." | "._QXZ("Pen.",5)." % |$rpt_header_SHIFTS\n"; - $rpt_header.="| | | | | | "._QXZ("Total",8)." | "._QXZ("No filtr",8)." | "._QXZ("One-off",8)." | "._QXZ("Inactive",8)." | | |$rpt_header_SHIFTS_lower\n"; - $rpt_header.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; - - $CSV_header="\""._QXZ("$report_name")."\"\n"; - $CSV_header.="\"Date: ".date("m/d/Y")."\",\"\",\"Time: ".date("H:i a")."\"\n\n"; - $CSV_header.="\""._QXZ("Call list")."\",\""._QXZ("List description")."\",\""._QXZ("Campaign")."\",\""._QXZ("Last call date")."\",\""._QXZ("Start Inv")."\",\""._QXZ("Call Inv Total")."\",\""._QXZ("Call Inv - No filter")."\",\""._QXZ("Call Inv - One-offs")."\",\""._QXZ("Call Inv - Inactive dialable statuses")."\",\""._QXZ("Dial Avg")."\",\""._QXZ("Pen.")." %\",".substr($CSV_header_SHIFTS,0,-1)."\n"; - - $rpt_footer ="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; - - #### PRINT TOTALS #### - $total_average_call_count=sprintf("%.1f", MathZDC($total_total_calls, $total_list_start_inv)); - $total_penetration=sprintf("%.2f", (MathZDC(100*($total_list_start_inv-$total_dialable_count), $total_list_start_inv))); - $rpt_footer.="|"._QXZ("TOTALS",76)." | ".sprintf("%9s", $total_list_start_inv)." | ".sprintf("%8s", $total_dialable_count)." | ".sprintf("%8s", $total_dialable_count_nofilter)." | ".sprintf("%8s", $total_dialable_count_oneoff)." | ".sprintf("%8s", $total_dialable_count_inactive)." | ".sprintf("%8s", $total_average_call_count)." | ".sprintf("%6s", $total_penetration)."% |"; - $CSV_body.="\"\",\"\",\"\",\""._QXZ("TOTALS")."\",\"$total_list_start_inv\",\"$total_dialable_count\",\"$total_dialable_count_nofilter\",\"$total_dialable_count_oneoff\",\"$total_dialable_count_inactive\",\"$total_average_call_count\",\"$total_penetration\""; - $b=0; - while ($b < count($shift_ary)) - { - $total_varname="total_".$shift_ary[$b]; - $rpt_footer.=" ".sprintf("%8s", $$total_varname)." |"; - $CSV_body.=",\"".$$total_varname."\""; - $b++; - } - $CSV_body.="\n"; - $rpt_footer.="\n"; - ###################### - - $rpt_footer.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; - } -$HTML_header.="
\n"; -############################### - -$HTML_text=""._QXZ("$report_name")." $NWB#dialer_inventory_report$NWE\n"; -$HTML_text.="
"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="
\n"; -$HTML_text.=" \n"; -$HTML_text.=" \n"; -if ($report_type=='LIST') {$cmp_checked=""; $list_checked="checked";} else {$cmp_checked="checked"; $list_checked="";} -$HTML_text.=" \n"; -$HTML_text.=" \n"; -$HTML_text.="
"._QXZ("Report type").":
"._QXZ("Campaigns")."
"._QXZ("List")."
\n"; -$HTML_text.="
 \n"; -$HTML_text.="$campaign_span_txt\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.=" \n"; -$HTML_text.=" \n"; -if ($time_setting=='LOCAL') {$svr_checked=""; $local_checked="checked";} else {$svr_checked="checked"; $local_checked="";} -if ($override_24hours) {$override_checked="checked";} -$HTML_text.=" \n"; -$HTML_text.=" \n"; -$HTML_text.=" \n"; -$HTML_text.="
"._QXZ("Time setting").":
"._QXZ("Server")."
"._QXZ("Local")."
"._QXZ("Ignore local campaign call time")."
("._QXZ("default to 24 hours").")
\n"; -$HTML_text.="
\n"; -$HTML_text.=" \n"; -$HTML_text.=" \n"; -if ($report_source=='REALTIME') {$ss_checked=""; $rt_checked="checked";} else {$ss_checked="checked"; $rt_checked="";} -$HTML_text.=" \n"; - -if ($inventory_allow_realtime > 0) - { - $HTML_text.=" \n"; - } -else - { - $HTML_text.=" \n"; - } - -$HTML_text.="
"._QXZ("Report source").":
"._QXZ("Snapshot")."
"._QXZ("Real-time")."
 
$snapshot_span_txt\n"; -$HTML_text.="
\n"; -$HTML_text.="
\n"; -$HTML_text.="           "._QXZ("DOWNLOAD")." | "._QXZ("REPORTS")."

\n"; -$HTML_text.="\n"; -$HTML_text.="
\n"; -$HTML_text.="
\n\n";
-
-$HTML_text.="$rpt_header";
-$HTML_text.="$rpt_body";
-$HTML_text.="$rpt_footer";
-
-$time_end = microtime(true);
-$ENDtime = date("U");
-$time = $ENDtime - $STARTtime;
-
-$HTML_text.=_QXZ("Executed in")." $time "._QXZ("seconds")."\n";
-$HTML_text.="
\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; - - -if ($file_download>0) - { - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "AST_DIALERinventory_$US$FILE_TIME.csv"; - $CSV_text=$CSV_header.$CSV_body; - $CSV_text=preg_replace('/^\s+/', '', $CSV_text); - $CSV_text=preg_replace('/\s+,/', ',', $CSV_text); - $CSV_text=preg_replace('/,\s+/', ',', $CSV_text); - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - } -else - { - $short_header=1; - - echo $HTML_header; - require("admin_header.php"); - echo $HTML_text; - } - -if ($db_source == 'S') - { - mysqli_close($link); - $use_slave_server=0; - $db_source = 'M'; - require("dbconnect_mysqli.php"); - } - -$endMS = microtime(); -$startMSary = explode(" ",$startMS); -$endMSary = explode(" ",$endMS); -$runS = ($endMSary[0] - $startMSary[0]); -$runM = ($endMSary[1] - $startMSary[1]); -$TOTALrun = ($runS + $runM); - -$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); - -exit; - -?> - - + LICENSE: AGPLv2 +# Matt Florell +# +# NOTES: +# - For snapshots, the AST_dialer_inventory_snapshot.pl script should be put in +# the crontab and run on a nightly basis after-hours +# +# +# CHANGES +# 111013-0054 - First build +# 111106-1327 - Reformatting, other minor changes +# 111230-1145 - Debugging additions and more minor changes +# 120221-2237 - Added totals, list options, other small changes +# 130414-0131 - Added report logging +# 130610-1021 - Finalized changing of all ereg instances to preg +# 130621-0800 - Added filtering of input to prevent SQL injection attacks and new user auth +# 130902-0735 - Changed to mysqli PHP functions +# 140108-0743 - Added webserver and hostname to report logging +# 140328-0005 - Converted division calculations to use MathZDC function +# 141114-0006 - Finalized adding QXZ translation to all admin files +# 141230-1509 - Added code for on-the-fly language translations display +# 160227-1933 - Uniform form format +# 170409-1538 - Added IP List validation code +# 170829-0040 - Added screen color settings +# 191013-0845 - Fixes for PHP7 +# + +$startMS = microtime(); + +error_reporting(0); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["report_type"])) {$report_type=$_GET["report_type"];} + elseif (isset($_POST["report_type"])) {$report_type=$_POST["report_type"];} +if (isset($_GET["selected_list"])) {$selected_list=$_GET["selected_list"];} + elseif (isset($_POST["selected_list"])) {$selected_list=$_POST["selected_list"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["time_setting"])) {$time_setting=$_GET["time_setting"];} + elseif (isset($_POST["time_setting"])) {$time_setting=$_POST["time_setting"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["report_source"])) {$report_source=$_GET["report_source"];} + elseif (isset($_POST["report_source"])) {$report_source=$_POST["report_source"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["DBX"])) {$DBX=$_GET["DBX"];} + elseif (isset($_POST["DBX"])) {$DBX=$_POST["DBX"];} +if (isset($_GET["snapshot_time"])) {$snapshot_time=$_GET["snapshot_time"];} + elseif (isset($_POST["snapshot_time"])) {$snapshot_time=$_POST["snapshot_time"];} +if (isset($_GET["override_24hours"])) {$override_24hours=$_GET["override_24hours"];} + elseif (isset($_POST["override_24hours"])) {$override_24hours=$_POST["override_24hours"];} + +$MT[0]=''; +$NOW_DATE = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$time_start = microtime(true); +$STARTtime = date("U"); +if (!isset($group)) {$group = array();} +if (!isset($query_date)) {$query_date = $NOW_DATE;} +if (!isset($end_date)) {$end_date = $NOW_DATE;} + + +$report_name = 'Dialer Inventory Report'; +$db_source = 'M'; + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_header.="$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $SSenable_languages = $row[4]; + $SSlanguage_method = $row[5]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +if ($non_latin < 1) + { + $PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER); + $PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW); + } +else + { + $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); + $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); + } + +$stmt="SELECT selected_language from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$sl_ct = mysqli_num_rows($rslt); +if ($sl_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $VUselected_language = $row[0]; + } + +$auth=0; +$reports_auth=0; +$admin_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $admin_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + if ($reports_auth < 1) + { + $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( ($reports_auth > 0) and ($admin_auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +##### BEGIN log visit to the vicidial_report_log table ##### +$LOGip = getenv("REMOTE_ADDR"); +$LOGbrowser = getenv("HTTP_USER_AGENT"); +$LOGscript_name = getenv("SCRIPT_NAME"); +$LOGserver_name = getenv("SERVER_NAME"); +$LOGserver_port = getenv("SERVER_PORT"); +$LOGrequest_uri = getenv("REQUEST_URI"); +$LOGhttp_referer = getenv("HTTP_REFERER"); +$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); +$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); +$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); +if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} +else {$LOGserver_port = ":$LOGserver_port";} +$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; + +$LOGhostname = php_uname('n'); +if (strlen($LOGhostname)<1) {$LOGhostname='X';} +if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} + +$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$webserver_id_ct = mysqli_num_rows($rslt); +if ($webserver_id_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $webserver_id = $row[0]; + } +else + { + ##### insert webserver entry + $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $affected_rows = mysqli_affected_rows($link); + $webserver_id = mysqli_insert_id($link); + } + +$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$report_log_id = mysqli_insert_id($link); +##### END log visit to the vicidial_report_log table ##### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysqli_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect_mysqli.php"); + #$HTML_header.="\n"; + } + +$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {$HTML_header.="|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGuser_group = $row[0]; + +$stmt="SELECT allowed_campaigns,allowed_reports from vicidial_user_groups where user_group='$LOGuser_group';"; +if ($DB) {$HTML_header.="|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGallowed_campaigns = $row[0]; +$LOGallowed_reports = $row[1]; + +if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) + { + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; + exit; + } + +$inventory_allow_realtime = 0; +if (file_exists('options.php')) + { + require('options.php'); + } + +$LOGallowed_campaignsSQL=''; +$whereLOGallowed_campaignsSQL=''; +if ( (!preg_match('/\-ALL/i', $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')"; + } +$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + $group_string .= "$group[$i]|"; + $i++; + } + +$stmt="SELECT campaign_id from vicidial_campaigns where campaign_id in (SELECT distinct campaign_id from vicidial_lists where inventory_report='Y') $LOGallowed_campaignsSQL order by campaign_id;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) { echo "$stmt\n";} +$campaigns_to_print = mysqli_num_rows($rslt); +$i=0; +$groups=array(); +while ($i < $campaigns_to_print) + { + $row=mysqli_fetch_row($rslt); + $groups[$i] =$row[0]; + if (preg_match('/\-ALL/',$group_string) ) + {$group[$i] = $groups[$i];} + $i++; + } + + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) + { + $group_string .= "$group[$i]|"; + $group_SQL .= "'$group[$i]',"; + $groupQS .= "&group[]=$group[$i]"; + } + $i++; + } + +if ( (preg_match('/\-\-ALL\-\-/',$group_string) ) or ($group_ct < 1) ) + {$group_SQL = "";} +else + { + $group_SQL = preg_replace('/,$/i', '',$group_SQL); + $group_SQL = "and campaign_id IN($group_SQL)"; + } + +$stmt="SELECT list_id, list_name from vicidial_lists where inventory_report='Y' $LOGallowed_campaignsSQL order by list_id, list_name;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_header.="$stmt\n";} +$lists_to_print = mysqli_num_rows($rslt); +$i=0; +$lists=array(); +$list_names=array(); +while ($i < $lists_to_print) + { + $row=mysqli_fetch_row($rslt); + $lists[$i] = $row[0]; + $list_names[$i] = $row[1]; + $i++; + } + +$campaign_span_txt=_QXZ("Campaigns").":
"; +$campaign_span_txt.=""; + +$list_span_txt=_QXZ("Lists").":
"; +$list_span_txt.=""; + +$snapshot_span_txt=_QXZ("Snapshot time").":
"; +$snapshot_stmt="SELECT distinct snapshot_time from dialable_inventory_snapshots order by snapshot_time desc limit 100;"; +if ($DBX > 0) {$HTML_header.= "|$snapshot_stmt|\n";} +$snapshot_rslt=mysql_to_mysqli($snapshot_stmt, $link); +$snapshot_span_txt.="\n"; + +require("screen_colors.php"); + +$NWB = "   \"HELP\""; + +$HTML_header.="\n"; +$HTML_header.="\n"; +$HTML_header.="\n"; + +if ($report_type=='LIST') {$onload="onload=\"ToggleSpan('list_span', 'campaign_span')\"";} + +$HTML_header.="\n"; +$HTML_header.="\n"; +$HTML_header.="\n"; +$HTML_header.=""._QXZ("$report_name")."\n"; +$HTML_header.="
\n";
+
+$rpt_header="";
+####### STAT GENERATION #######
+require("count_functions.inc");
+function GetListCount($list_id, $inventory_ptnstr) 
+	{
+	global $list_start_inv;
+	global $new_count;
+	global $link;
+	global $total_calls;
+	$ct_stmt="SELECT status, called_count, count(*) From vicidial_list where list_id='$list_id' group by status, called_count order by status, called_count;";
+	if ($DBX > 0) {$HTML_header.= "|$ct_stmt|\n";}
+	$ct_rslt=mysql_to_mysqli($ct_stmt, $link);
+	$new_count=0; $total_calls=0;
+	while ($ct_row=mysqli_fetch_row($ct_rslt)) 
+		{
+		$list_start_inv+=$ct_row[2];
+		$total_calls+=($ct_row[1]*$ct_row[2]);
+		if (preg_match('/|$ct_row[0]|/', $inventory_ptnstr) && $ct_row[1]=="0") {$new_count+=$ct_row[2];} 
+		}
+	}
+
+if ($SUBMIT) 
+	{
+
+	$total_list_start_inv=0;
+	$total_dialable_count=0;
+	$total_dialable_count_nofilter=0;
+	$total_dialable_count_oneoff=0;
+	$total_dialable_count_inactive=0;
+	$total_total_calls=0;
+	$total_average_call_count=0;
+	$total_penetration=0;
+
+	$shift_ary=array();
+	if ($snapshot_time && $report_source=="SNAPSHOT") 
+		{
+		$rpt_header=_QXZ("SNAPSHOT from")." $snapshot_time\n";
+		$stmt="SELECT distinct shift_data from dialable_inventory_snapshots where snapshot_time='$snapshot_time' and time_setting='$time_setting' $time_clause order by campaign_id, list_id;";
+		if ($DBX > 0) {$HTML_header.= "|$stmt|\n";}
+		$rslt=mysql_to_mysqli($stmt, $link);
+		$shift_SQL_str="";
+		while ($shift_row=mysqli_fetch_array($rslt)) 
+			{
+			$shift_data1=explode("|", $shift_row["shift_data"]);
+			for ($i=0; $i 0) {$HTML_header.= "|$shift_stmt|\n";}
+		$shift_rslt=mysql_to_mysqli($shift_stmt, $link);
+		$c=0;
+		while($shift_row=mysqli_fetch_array($shift_rslt)) 
+			{
+			$rpt_header_SHIFTS.=" ".sprintf("%8s", substr($shift_row["shift_id"],0,8))." |";
+			$CSV_header_SHIFTS.="\"$shift_row[shift_id]\",";
+			$rpt_header_SHIFTS_lower.="          |";
+			$rpt_header_BORDER.="----------+";
+			$shift_ary[$c]=$shift_row["shift_id"];
+			$total_varname="total_".$shift_row["shift_id"];
+			$$total_varname=0;
+			if ($DB > 0) {echo "
-$c-$shift_ary[$c]-$shift_row[shift_id]-\n";} + $c++; + } + + if ($report_type=="CAMPAIGNS") {$time_clause=$group_SQL;} + if ($report_type=="LIST") {$time_clause="and list_id='$selected_list'";} + $stmt="SELECT snapshot_id,snapshot_time,list_id,list_name,list_description,campaign_id,list_lastcalldate,list_start_inv,dialable_count,dialable_count_nofilter,dialable_count_oneoff,dialable_count_inactive,average_call_count,penetration,shift_data,time_setting from dialable_inventory_snapshots where snapshot_time='$snapshot_time' and time_setting='$time_setting' $time_clause order by campaign_id, list_id;"; + if ($DBX > 0) {$HTML_header.= "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + while ($row=mysqli_fetch_array($rslt)) + { + $row["list_description"]=substr($row["list_description"], 0, 30); + if (strlen($row["list_description"])>0) {$list_info=$row["list_description"];} else {$list_info=$row["list_name"];} + $rpt_body.="| ".sprintf("%9s", $row["list_id"])." | ".sprintf("%-30s", $list_info)." | ".sprintf("%8s", $row["campaign_id"])." | ".$row["list_lastcalldate"]." | ".sprintf("%9s", $row["list_start_inv"])." | ".sprintf("%8s", $row["dialable_count"])." | ".sprintf("%8s", $row["dialable_count_nofilter"])." | ".sprintf("%8s", $row["dialable_count_oneoff"])." | ".sprintf("%8s", $row["dialable_count_inactive"])." | ".sprintf("%8s", $row["average_call_count"])." | ".sprintf("%6s", $row["penetration"])."% |"; + $CSV_body.="\"$row[list_id]\",\"$list_info\",\"$row[last_calldate]\",\"$row[campaign_id]\",\"$row[list_start_inv]\",\"$row[dialable_count]\",\"$row[dialable_count_nofilter]\",\"$row[dialable_count_oneoff]\",\"$row[dialable_count_inactive]\",\"$row[average_call_count]\",\"$row[penetration] %\""; + + $total_list_start_inv+=$row["list_start_inv"]; + $total_dialable_count+=$row["dialable_count"]; + $total_dialable_count_nofilter+=$row["dialable_count_nofilter"]; + $total_dialable_count_oneoff+=$row["dialable_count_oneoff"]; + $total_dialable_count_inactive+=$row["dialable_count_inactive"]; + $total_total_calls+=($row["average_call_count"]*$row["list_start_inv"]); + + $shift_data_a=explode("|", $row["shift_data"]); + $b=0; + while ($b < count($shift_ary)) + { + $a=0; + $no_match=0; + while ($a < count($shift_data_a)) + { + $shift_data_b=explode(",", $shift_data_a[$a]); + $line_match=0; + if ($shift_ary[$b] == "$shift_data_b[0]") + { + $rpt_body.=" ".sprintf("%8s", $shift_data_b[1])." |"; + $CSV_body.=",\"$shift_data_b[1]\""; + $total_varname="total_".$shift_data_b[0]; + $$total_varname+=$shift_data_b[1]; + $line_match++; + $no_match++; + } + if ($DB > 0) {echo "
-$a-$b-$shift_ary[$b]-$shift_data_b[0]($shift_data_b[1])-$line_match-\n";} + $a++; + } + if ($no_match==0) + { + $rpt_body.=" ".sprintf("%8s", "0")." |"; + $CSV_body.=",\"0\""; + } + $b++; + } + $rpt_body.="\n"; + $CSV_body.="\n"; + } + } + else + { + $single_status=1; + + ## If time setting is set to 'Local', compile a list of time zone offsets and make an array of those offsets with the amount of time that needs to be added or subtracted + if ($time_setting=="LOCAL") + { + $gmt_stmt="SELECT default_local_gmt from system_settings;"; + $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); + $gmt_row=mysqli_fetch_row($gmt_rslt); + $local_offset=$gmt_row[0]; + + if ($report_type=="CAMPAIGNS") {$time_clause="where list_id in (SELECT list_id from vicidial_lists where inventory_report='Y' ".substr($group_SQL,4).")";} + if ($report_type=="LIST") {$time_clause="where list_id='$selected_list'";} + $gmt_stmt="SELECT distinct gmt_offset_now, gmt_offset_now-($local_offset) from vicidial_list $time_clause ;"; + if ($DB) {$HTML_header.=$gmt_stmt."
\n";} + $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); + while ($gmt_row=mysqli_fetch_row($gmt_rslt)) + { + $gmt_row[1]=preg_replace('/25$/', '15', $gmt_row[1]); + $gmt_row[1]=preg_replace('/75$/', '45', $gmt_row[1]); + $gmt_row[1]=preg_replace('/\.5$/', '.30', $gmt_row[1]); + $gmt_row[1]=preg_replace('/\./', ':', $gmt_row[1]); + $gri = $gmt_row[0]; + $gmt_array[$gri]=$gmt_row[1]; + } + } + + # Get shift information + $shift_stmt="SELECT shift_id, shift_name, str_to_date(shift_start_time, '%H%i') as shift_start_time, addtime(str_to_date(shift_start_time, '%H%i'), shift_length) as shift_end_time, if(addtime(str_to_date(shift_start_time, '%H%i'), shift_length)>'23:59:59', '1', '0') as day_offset, shift_weekdays from vicidial_shifts where report_option='Y' order by report_rank, shift_start_time asc;"; + if ($DB) {$HTML_header.="$shift_stmt;\n";} + $shift_rslt=mysql_to_mysqli($shift_stmt, $link); + while($shift_row=mysqli_fetch_array($shift_rslt)) + { + $rpt_header_SHIFTS.=" ".sprintf("%8s", substr($shift_row["shift_id"],0,8))." |"; + $rpt_header_SHIFTS_lower.=" |"; + $CSV_header_SHIFTS.="\"$shift_row[shift_id]\","; + $rpt_header_BORDER.="----------+"; + $shift_ary[$shift_row["shift_id"]][0]=$shift_row["shift_name"]; + $shift_ary[$shift_row["shift_id"]][1]=$shift_row["shift_start_time"]; + $shift_ary[$shift_row["shift_id"]][2]=$shift_row["shift_end_time"]; + $shift_ary[$shift_row["shift_id"]][3]=$shift_row["day_offset"]; + $shift_ary[$shift_row["shift_id"]][4]=$shift_row["shift_weekdays"]; + } + + $rpt_body=""; + if ($group_ct>0 && $report_type=="CAMPAIGNS") + { + for ($i=0; $i<$group_ct; $i++) + { + $campaign_stmt="SELECT call_count_limit, call_count_target, dial_statuses, local_call_time, drop_lockout_time from vicidial_campaigns where campaign_id='$group[$i]' $LOGallowed_campaignsSQL;"; + if ($DB) {$HTML_header.="$campaign_stmt;\n";} + $campaign_rslt=mysql_to_mysqli($campaign_stmt, $link); + $campaign_row=mysqli_fetch_row($campaign_rslt); + $call_count_limit=$campaign_row[0]; + $call_count_target=$campaign_row[1]; + $active_dial_statuses=$campaign_row[2]; + $local_call_time=$campaign_row[3]; if ($override_24hours) {$local_call_time="24hours";} + $drop_lockout_time=$campaign_row[4]; + + $stmt="SELECT distinct status from vicidial_statuses where completed='N' UNION SELECT distinct status from vicidial_campaign_statuses where completed='N' and campaign_id='$group[$i]' $LOGallowed_campaignsSQL"; + if ($DB) {$HTML_header.="$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $dial_statuses=" "; + $inventory_statuses=" "; + $inventory_ptnstr="|"; + $inactive_dial_statuses=" "; + while ($row=mysqli_fetch_row($rslt)) + { + $dial_statuses.="$row[0] "; + $inventory_statuses.="'$row[0]',"; + $inventory_ptnstr.="$row[0]|"; + if (!preg_match("/ $row[0] /", "$active_dial_statuses")) {$inactive_dial_statuses.="$row[0] ";} + } + $inventory_statuses=substr($inventory_statuses, 0, -1); + if ($DB) {$HTML_header.= " "._QXZ("CAMPAIGN DIAL STATUSES",30,"r").": |$active_dial_statuses|\n";} + if ($DB) {$HTML_header.= " "._QXZ("INVENTORY STATUSES RESULTS",30,"r").": |$inventory_statuses|\n";} + if ($DB) {$HTML_header.= " "._QXZ("INACTIVE STATUSES RESULTS",30,"r").": |$inactive_dial_statuses|\n";} + + $filter_stmt="SELECT lead_filter_sql from vicidial_campaigns v, vicidial_lead_filters vlf where v.campaign_id='$group[$i]' and v.lead_filter_id=vlf.lead_filter_id limit 1;"; + if ($DB) {$HTML_header.="$filter_stmt;\n";} + $filter_rslt=mysql_to_mysqli($filter_stmt, $link); + $filter_row=mysqli_fetch_row($filter_rslt); + if (strlen($filter_row[0])>0) {$filter_SQL=" and $filter_row[0]";} else {$filter_SQL="";} + $filter_SQL = preg_replace("/\\\/",'',$filter_SQL); + + $lists_stmt="SELECT list_id, list_name, list_description, if(list_lastcalldate is null, '*** Not called *** ', list_lastcalldate) as list_lastcalldate from vicidial_lists where campaign_id='$group[$i]' and inventory_report='Y' $LOGallowed_campaignsSQL order by list_id asc;"; + if ($DB) {$HTML_header.="$lists_stmt;\n";} + $lists_rslt=mysql_to_mysqli($lists_stmt, $link); + while ($lists_row=mysqli_fetch_array($lists_rslt)) + { + $list_id=$lists_row["list_id"]; + $list_name=$lists_row["list_name"]; + $lists_row["list_description"]=substr($lists_row["list_description"], 0, 30); + $list_description=$lists_row["list_description"]; + $last_calldate=$lists_row["list_lastcalldate"]; + if (strlen($list_description)>0) {$list_info=$list_description;} else {$list_info=$list_name;} + + $list_start_inv=0; + $only_return=1; + GetListCount($list_id, $inventory_ptnstr); + $average_calls=sprintf("%.1f", MathZDC($total_calls, $list_start_inv)); + $Xdialable_count_nofilter = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"",$only_return); + if (strlen($inactive_dial_statuses)>1) + { + $Xdialable_inactive_count = dialable_leads($DB,$link,$local_call_time,"$inactive_dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL",$only_return); + } + else + { + $Xdialable_inactive_count = 0; + } + + $oneoff_SQL=$filter_SQL." and (called_count < $call_count_limit-1) "; + $oneoff_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$oneoff_SQL",$only_return); + + $full_dialable_SQL=""; + $Xdialable_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$list_id,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL",$only_return); + + $penetration=sprintf("%.2f", (MathZDC(100*($list_start_inv-$Xdialable_count), $list_start_inv))); + + $rpt_body.="| ".sprintf("%9s", $list_id)." | ".sprintf("%-30s", $list_info)." | ".sprintf("%8s", $group[$i])." | ".$last_calldate." | ".sprintf("%9s", $list_start_inv)." | ".sprintf("%8s", $Xdialable_count)." | ".sprintf("%8s", $Xdialable_count_nofilter)." | ".sprintf("%8s", $oneoff_count)." | ".sprintf("%8s", $Xdialable_inactive_count)." | ".sprintf("%8s", $average_calls)." | ".sprintf("%6s", $penetration)."% |"; + $CSV_body.="\"$list_id\",\"$list_info\",\"$last_calldate\",\"$group[$i]\",\"$list_start_inv\",\"$Xdialable_count\",\"$Xdialable_count_nofilter\",\"$oneoff_count\",\"$Xdialable_inactive_count\",\"$average_calls\",\"$penetration %\""; + + $total_list_start_inv+=$list_start_inv; + $total_dialable_count+=$Xdialable_count; + $total_dialable_count_nofilter+=$Xdialable_count_nofilter; + $total_dialable_count_oneoff+=$oneoff_count; + $total_dialable_count_inactive+=$Xdialable_inactive_count; + $total_total_calls+=$total_calls; + + # $stat_stmt="SELECT call_date, dayofweek(call_date) from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where list_id='$list_id' and called_count<='$called_count_limit' and status in ($inventory_statuses) $filter_SQL"; + # SELECT lead_id, count(*) as count from vicidial_log where extract(HOUR_MINUTE FROM call_date)>='900' and extract(HOUR_MINUTE FROM call_date)<='1700' and dayofweek(call_date) in (2,3,4,5,6) and lead_id in (SELECT lead_id from vicidial_list where list_id=41073) group by lead_id order by lead_id; + + $shift_ary2=$shift_ary; +# while (list($key, $val)=each($shift_ary2)) + foreach ($shift_ary2 as $key => $val) + { + $total_shift_count=0; + $gmt_stmt="SELECT distinct gmt_offset_now from vicidial_list where list_id='$list_id';"; + if ($DB) {$HTML_header.="$gmt_stmt\n";} + $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); + while ($gmt_row=mysqli_fetch_row($gmt_rslt)) + { + if ($time_setting=="LOCAL") + { + $gri = $gmt_row[0]; + $offset_hours=$gmt_array[$gri]; + } + else + { + $offset_hours=0; + } + + if (strlen($val[4])>0) + { + if ($val[3]==0) + { + $shift_days_SQL=" and time(addtime(call_date, '$offset_hours'))>='$val[1]' and time(addtime(call_date, '$offset_hours'))<='$val[2]' "; + $day_str=""; + for ($j=0; $j=addtime('09:00', '00:04:00') + } + $shift_days_SQL=substr($shift_days_SQL, 0, -3).")"; + } + } + else + { + $shift_days_SQL=""; + } + + $shift_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target';"; + + $shift_rslt=mysql_to_mysqli($shift_stmt, $link); + $shift_row=mysqli_fetch_row($shift_rslt); + if ($DB) {$HTML_header.="$shift_stmt
$shift_row[0]
\n";} + $total_shift_count+=$shift_row[0]; + } + $shift_count=$Xdialable_count-$total_shift_count; + $rpt_body.=" ".sprintf("%8s", $shift_count)." |"; + $total_varname="total_".$key; + $$total_varname+=$shift_count; + $CSV_body.=",\"$shift_count\""; + } + $rpt_body.="\n"; + $CSV_body.="\n"; + if (!$file_download) {echo $HTML_header; $HTML_header=""; flush();} + } + } + } + else if ($selected_list && $report_type=="LIST") + { + $campaign_stmt="SELECT call_count_limit, call_count_target, dial_statuses, local_call_time, drop_lockout_time, v.campaign_id from vicidial_campaigns v, vicidial_lists vl where inventory_report='Y' and vl.list_id='$selected_list' and vl.campaign_id=v.campaign_id;"; + if ($DB) {$HTML_header.="$campaign_stmt;\n";} + $campaign_rslt=mysql_to_mysqli($campaign_stmt, $link); + $campaign_row=mysqli_fetch_row($campaign_rslt); + $call_count_limit=$campaign_row[0]; + $call_count_target=$campaign_row[1]; + $active_dial_statuses=$campaign_row[2]; + $local_call_time=$campaign_row[3]; if ($override_24hours) {$local_call_time="24hours";} + $drop_lockout_time=$campaign_row[4]; + $campaign_id=$campaign_row[5]; + + $stmt="SELECT distinct status from vicidial_statuses where completed='N' UNION SELECT distinct status from vicidial_campaign_statuses where completed='N' and campaign_id=(SELECT campaign_id from vicidial_lists where list_id='$selected_list' and inventory_report='Y' $LOGallowed_campaignsSQL);"; + if ($DB) {$HTML_header.="$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $inactive_dial_statuses=" "; + $dial_statuses=" "; + $inventory_statuses=""; + $inventory_ptnstr="|"; + while ($row=mysqli_fetch_row($rslt)) + { + $dial_statuses.="$row[0] "; + $inventory_statuses.="'$row[0]',"; + $inventory_ptnstr.="$row[0]|"; + if (!preg_match("/ $row[0] /", "$active_dial_statuses")) {$inactive_dial_statuses.="$row[0] ";} + } + $inventory_statuses=substr($inventory_statuses, 0, -1); + if ($DB) {$HTML_header.= " "._QXZ("CAMPAIGN DIAL STATUSES",30,"r").": |$active_dial_statuses|\n";} + if ($DB) {$HTML_header.= " "._QXZ("DIAL STATUSES",30,"r").": |$dial_statuses|\n";} + if ($DB) {$HTML_header.= " "._QXZ("INVENTORY STATUSES RESULTS",30,"r").": |$inventory_statuses|\n";} + if ($DB) {$HTML_header.= " "._QXZ("INACTIVE STATUSES RESULTS",30,"r").": |$inactive_dial_statuses|\n";} + + if ($DB) {$HTML_header.="$campaign_stmt; - $dial_statuses\n";} + + $filter_stmt="SELECT lead_filter_sql from vicidial_campaigns v, vicidial_lead_filters vlf where v.campaign_id='$campaign_id' and v.lead_filter_id=vlf.lead_filter_id limit 1;"; + if ($DB) {$HTML_header.="$filter_stmt;\n";} + $filter_rslt=mysql_to_mysqli($filter_stmt, $link); + $filter_row=mysqli_fetch_row($filter_rslt); + if (strlen($filter_row[0])>0) {$filter_SQL=" and $filter_row[0]";} else {$filter_SQL="";} + $filter_SQL = preg_replace("/\\\/",'',$filter_SQL); + + $lists_stmt="SELECT list_id, list_name, list_description, if(list_lastcalldate is null, '*** "._QXZ("Not called")." *** ', list_lastcalldate) as list_lastcalldate, campaign_id from vicidial_lists where list_id='$selected_list' and inventory_report='Y' $LOGallowed_campaignsSQL order by list_id asc;"; + if ($DB) {$HTML_header.="$lists_stmt;\n";} + $lists_rslt=mysql_to_mysqli($lists_stmt, $link); + while ($lists_row=mysqli_fetch_array($lists_rslt)) + { + $list_id=$lists_row["list_id"]; + $list_name=$lists_row["list_name"]; + $lists_row["list_description"]=substr($lists_row["list_description"], 0, 30); + $list_description=$lists_row["list_description"]; + $last_calldate=$lists_row["list_lastcalldate"]; + $campaign_id=$lists_row["campaign_id"]; + if (strlen($list_description)>0) {$list_info=$list_description;} else {$list_info=$list_name;} + $list_call_inv=0; + GetListCount($list_id, $inventory_ptnstr); + $average_calls=sprintf("%.1f", MathZDC($total_calls, $list_start_inv)); + + ### For TOTAL counts, needs to be here instead of with other "total" variables further down in this particular report + $total_total_calls+=$total_calls; + $only_return=1; + + $Xdialable_count_nofilter = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"",$only_return); + if (strlen($inactive_dial_statuses)>1) + { + $Xdialable_inactive_count = dialable_leads($DB,$link,$local_call_time,"$inactive_dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL",$only_return); + } + else + { + $Xdialable_inactive_count = 0; + } + + $oneoff_SQL=$filter_SQL." and (called_count < $call_count_limit-1) "; + $oneoff_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$oneoff_SQL",$only_return); + + $full_dialable_SQL=""; + $Xdialable_count = dialable_leads($DB,$link,$local_call_time,"$dial_statuses",$selected_list,$drop_lockout_time,$call_count_limit,$single_status,"$filter_SQL",$only_return); + if ($DB > 0) {echo _QXZ("FULL DIALABLE SQL").": |$full_dialable_SQL|";} + } + + $penetration=sprintf("%.2f", (MathZDC(100*($list_start_inv-$Xdialable_count), $list_start_inv))); + + $rpt_body.="| ".sprintf("%9s", $list_id)." | ".sprintf("%-30s", $list_info)." | ".sprintf("%8s", $campaign_id)." | ".$last_calldate." | ".sprintf("%9s", $list_start_inv)." | ".sprintf("%8s", $Xdialable_count)." | ".sprintf("%8s", $Xdialable_count_nofilter)." | ".sprintf("%8s", $oneoff_count)." | ".sprintf("%8s", $Xdialable_inactive_count)." | ".sprintf("%8s", $average_calls)." | ".sprintf("%6s", $penetration)."% |"; + $CSV_body.="\"$list_id\",\"$list_info\",\"$last_calldate\",\"$campaign_id\",\"$list_start_inv\",\"$Xdialable_count\",\"$Xdialable_count_nofilter\",\"$oneoff_count\",\"$Xdialable_inactive_count\",\"$average_calls\",\"$penetration %\""; + + $total_list_start_inv+=$list_start_inv; + $total_dialable_count+=$Xdialable_count; + $total_dialable_count_nofilter+=$Xdialable_count_nofilter; + $total_dialable_count_oneoff+=$oneoff_count; + $total_dialable_count_inactive+=$Xdialable_inactive_count; + + $shift_ary2=$shift_ary; +# while (list($key, $val)=each($shift_ary2)) + foreach ($shift_ary2 as $key => $val) + { + $total_shift_count=0; + $total_nofilter_shift_count=0; + $total_oneoff_shift_count=0; + $total_undialable_shift_count=0; + $total_nofilter_undialable_shift_count=0; + $gmt_stmt="SELECT distinct gmt_offset_now from vicidial_list where list_id='$list_id';"; + if ($DB) {$HTML_header.="$gmt_stmt\n";} + $gmt_rslt=mysql_to_mysqli($gmt_stmt, $link); + while ($gmt_row=mysqli_fetch_row($gmt_rslt)) + { + if ($time_setting=="LOCAL") + { + $gri = $gmt_row[0]; + $offset_hours=$gmt_array[$gri]; + } + else + { + $offset_hours=0; + } + + if (strlen($val[4])>0) + { + if ($val[3]==0) + { + $shift_days_SQL=" and time(addtime(call_date, '$offset_hours'))>='$val[1]' and time(addtime(call_date, '$offset_hours'))<='$val[2]' "; + $day_str=""; + for ($i=0; $i=addtime('09:00', '00:04:00') + } + $shift_days_SQL=substr($shift_days_SQL, 0, -3).")"; + } + } + else + { + $shift_days_SQL=""; + } + +# $dialable_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; +# $dialable_nofilter_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]') $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; +# $undialable_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; +# $undialable_nofilter_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]') $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target'"; +# $oneoff_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='($call_count_target-1)'"; + $shift_stmt="SELECT count(*) from (SELECT lead_id, count(*) as count from vicidial_log where lead_id in (SELECT lead_id from vicidial_list where $full_dialable_SQL and gmt_offset_now='$gmt_row[0]' $filter_SQL) $shift_days_SQL group by lead_id) as count_table where count_table.count>='$call_count_target';"; + + $shift_rslt=mysql_to_mysqli($shift_stmt, $link); + $shift_row=mysqli_fetch_row($shift_rslt); + if ($DB) {$HTML_header.="$shift_stmt;
$shift_row[0]
\n";} + $total_shift_count+=$shift_row[0]; + } + $shift_count=$Xdialable_count-$total_shift_count; + $rpt_body.=" ".sprintf("%8s", $shift_count)." |"; + $total_varname="total_".$key; + $$total_varname+=$shift_count; + $CSV_body.=",\"$shift_count\""; + } + $rpt_body.="\n"; + $CSV_body.="\n"; + if (!$file_download) {echo $HTML_header; $HTML_header=""; flush();} + } + } + + $rpt_header.=_QXZ("Date").": ".date("m/d/Y")." -- "._QXZ("Time").": ".date("H:i a")."\n\n"; + $rpt_header.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; + $rpt_header.="| "._QXZ("Call list",9)." | "._QXZ("List description",30)." | "._QXZ("Campaign",8)." | "._QXZ("Last call date",19)." | "._QXZ("Start Inv",9)." | "._QXZ("Call Inv",8)." | "._QXZ("Call Inv",8)." | "._QXZ("Call Inv",8)." | "._QXZ("Call Inv",8)." | "._QXZ("Dial Avg",8)." | "._QXZ("Pen.",5)." % |$rpt_header_SHIFTS\n"; + $rpt_header.="| | | | | | "._QXZ("Total",8)." | "._QXZ("No filtr",8)." | "._QXZ("One-off",8)." | "._QXZ("Inactive",8)." | | |$rpt_header_SHIFTS_lower\n"; + $rpt_header.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; + + $CSV_header="\""._QXZ("$report_name")."\"\n"; + $CSV_header.="\"Date: ".date("m/d/Y")."\",\"\",\"Time: ".date("H:i a")."\"\n\n"; + $CSV_header.="\""._QXZ("Call list")."\",\""._QXZ("List description")."\",\""._QXZ("Campaign")."\",\""._QXZ("Last call date")."\",\""._QXZ("Start Inv")."\",\""._QXZ("Call Inv Total")."\",\""._QXZ("Call Inv - No filter")."\",\""._QXZ("Call Inv - One-offs")."\",\""._QXZ("Call Inv - Inactive dialable statuses")."\",\""._QXZ("Dial Avg")."\",\""._QXZ("Pen.")." %\",".substr($CSV_header_SHIFTS,0,-1)."\n"; + + $rpt_footer ="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; + + #### PRINT TOTALS #### + $total_average_call_count=sprintf("%.1f", MathZDC($total_total_calls, $total_list_start_inv)); + $total_penetration=sprintf("%.2f", (MathZDC(100*($total_list_start_inv-$total_dialable_count), $total_list_start_inv))); + $rpt_footer.="|"._QXZ("TOTALS",76)." | ".sprintf("%9s", $total_list_start_inv)." | ".sprintf("%8s", $total_dialable_count)." | ".sprintf("%8s", $total_dialable_count_nofilter)." | ".sprintf("%8s", $total_dialable_count_oneoff)." | ".sprintf("%8s", $total_dialable_count_inactive)." | ".sprintf("%8s", $total_average_call_count)." | ".sprintf("%6s", $total_penetration)."% |"; + $CSV_body.="\"\",\"\",\"\",\""._QXZ("TOTALS")."\",\"$total_list_start_inv\",\"$total_dialable_count\",\"$total_dialable_count_nofilter\",\"$total_dialable_count_oneoff\",\"$total_dialable_count_inactive\",\"$total_average_call_count\",\"$total_penetration\""; + $b=0; + while ($b < count($shift_ary)) + { + $total_varname="total_".$shift_ary[$b]; + $rpt_footer.=" ".sprintf("%8s", $$total_varname)." |"; + $CSV_body.=",\"".$$total_varname."\""; + $b++; + } + $CSV_body.="\n"; + $rpt_footer.="\n"; + ###################### + + $rpt_footer.="+-----------+--------------------------------+----------+---------------------+-----------+----------+----------+----------+----------+----------+---------+$rpt_header_BORDER\n"; + } +$HTML_header.="
\n"; +############################### + +$HTML_text=""._QXZ("$report_name")." $NWB#dialer_inventory_report$NWE\n"; +$HTML_text.="
"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="
\n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +if ($report_type=='LIST') {$cmp_checked=""; $list_checked="checked";} else {$cmp_checked="checked"; $list_checked="";} +$HTML_text.=" \n"; +$HTML_text.=" \n"; +$HTML_text.="
"._QXZ("Report type").":
"._QXZ("Campaigns")."
"._QXZ("List")."
\n"; +$HTML_text.="
 \n"; +$HTML_text.="$campaign_span_txt\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +if ($time_setting=='LOCAL') {$svr_checked=""; $local_checked="checked";} else {$svr_checked="checked"; $local_checked="";} +if ($override_24hours) {$override_checked="checked";} +$HTML_text.=" \n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +$HTML_text.="
"._QXZ("Time setting").":
"._QXZ("Server")."
"._QXZ("Local")."
"._QXZ("Ignore local campaign call time")."
("._QXZ("default to 24 hours").")
\n"; +$HTML_text.="
\n"; +$HTML_text.=" \n"; +$HTML_text.=" \n"; +if ($report_source=='REALTIME') {$ss_checked=""; $rt_checked="checked";} else {$ss_checked="checked"; $rt_checked="";} +$HTML_text.=" \n"; + +if ($inventory_allow_realtime > 0) + { + $HTML_text.=" \n"; + } +else + { + $HTML_text.=" \n"; + } + +$HTML_text.="
"._QXZ("Report source").":
"._QXZ("Snapshot")."
"._QXZ("Real-time")."
 
$snapshot_span_txt\n"; +$HTML_text.="
\n"; +$HTML_text.="
\n"; +$HTML_text.="           "._QXZ("DOWNLOAD")." | "._QXZ("REPORTS")."

\n"; +$HTML_text.="\n"; +$HTML_text.="
\n"; +$HTML_text.="
\n\n";
+
+$HTML_text.="$rpt_header";
+$HTML_text.="$rpt_body";
+$HTML_text.="$rpt_footer";
+
+$time_end = microtime(true);
+$ENDtime = date("U");
+$time = $ENDtime - $STARTtime;
+
+$HTML_text.=_QXZ("Executed in")." $time "._QXZ("seconds")."\n";
+$HTML_text.="
\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; + + +if ($file_download>0) + { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_DIALERinventory_$US$FILE_TIME.csv"; + $CSV_text=$CSV_header.$CSV_body; + $CSV_text=preg_replace('/^\s+/', '', $CSV_text); + $CSV_text=preg_replace('/\s+,/', ',', $CSV_text); + $CSV_text=preg_replace('/,\s+/', ',', $CSV_text); + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + } +else + { + $short_header=1; + + echo $HTML_header; + require("admin_header.php"); + echo $HTML_text; + } + +if ($db_source == 'S') + { + mysqli_close($link); + $use_slave_server=0; + $db_source = 'M'; + require("dbconnect_mysqli.php"); + } + +$endMS = microtime(); +$startMSary = explode(" ",$startMS); +$endMSary = explode(" ",$endMS); +$runS = ($endMSary[0] - $startMSary[0]); +$runM = ($endMSary[1] - $startMSary[1]); +$TOTALrun = ($runS + $runM); + +$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); + +exit; + +?> + + diff --git a/agc_2-X/trunk/www/vicidial/AST_hangup_cause_report.php b/agc_2-X/trunk/www/vicidial/AST_hangup_cause_report.php index de592b8c..9821e44c 100644 --- a/agc_2-X/trunk/www/vicidial/AST_hangup_cause_report.php +++ b/agc_2-X/trunk/www/vicidial/AST_hangup_cause_report.php @@ -1,930 +1,930 @@ - LICENSE: AGPLv2 -# -# CHANGES -# 120331-2301 - First build -# 130413-2348 - Added report logging -# 130419-2047 - Changed how menu lists are generated to speed up initial form load -# 132305-2305 - Finalized changing of all ereg instances to preg -# 130621-0749 - Added filtering of input to prevent SQL injection attacks and new user auth -# 130902-0731 - Changed to mysqli PHP functions -# 140108-0739 - Added webserver and hostname to report logging -# 140403-1830 - Fixed SIP hangup bug -# 141114-0837 - Finalized adding QXZ translation to all admin files -# 141230-1457 - Added code for on-the-fly language translations display -# 170409-1534 - Added IP List validation code -# 170818-2345 - Added HTML formatting -# 170829-0040 - Added screen color settings -# 191013-0858 - Fixes for PHP7 -# 201218-1700 - Modified to include caller ID in results -# - -$startMS = microtime(); - -$report_name='Hangup Cause Report'; - -require("dbconnect_mysqli.php"); -require("functions.php"); - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} - elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} - elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} -if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} - elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} -if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} - elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} -if (isset($_GET["hangup_cause"])) {$hangup_cause=$_GET["hangup_cause"];} - elseif (isset($_POST["hangup_cause"])) {$hangup_cause=$_POST["hangup_cause"];} -if (isset($_GET["sip_hangup_cause"])) {$sip_hangup_cause=$_GET["sip_hangup_cause"];} - elseif (isset($_POST["sip_hangup_cause"])) {$sip_hangup_cause=$_POST["sip_hangup_cause"];} -if (isset($_GET["dial_status"])) {$dial_status=$_GET["dial_status"];} - elseif (isset($_POST["dial_status"])) {$dial_status=$_POST["dial_status"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["lower_limit"])) {$lower_limit=$_GET["lower_limit"];} - elseif (isset($_POST["lower_limit"])) {$lower_limit=$_POST["lower_limit"];} -if (isset($_GET["upper_limit"])) {$upper_limit=$_GET["upper_limit"];} - elseif (isset($_POST["upper_limit"])) {$upper_limit=$_POST["upper_limit"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["submit"])) {$submit=$_GET["submit"];} - elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} -if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} -if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} - elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} - -$START_TIME=date("U"); - -############################################# -##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method FROM system_settings;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$MAIN.="$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $non_latin = $row[0]; - $outbound_autodial_active = $row[1]; - $slave_db_server = $row[2]; - $reports_use_slave_db = $row[3]; - $SSenable_languages = $row[4]; - $SSlanguage_method = $row[5]; - } -##### END SETTINGS LOOKUP ##### -########################################### - -##### Hangup Cause Dictionary ##### -$hangup_cause_dictionary = array( -0 => _QXZ("Unspecified. No other cause codes applicable."), -1 => _QXZ("Unallocated (unassigned) number."), -2 => _QXZ("No route to specified transit network (national use)."), -3 => _QXZ("No route to destination."), -6 => _QXZ("Channel unacceptable."), -7 => _QXZ("Call awarded, being delivered in an established channel."), -16 => _QXZ("Normal call clearing."), -17 => _QXZ("User busy."), -18 => _QXZ("No user responding."), -19 => _QXZ("No answer from user (user alerted)."), -20 => _QXZ("Subscriber absent."), -21 => _QXZ("Call rejected."), -22 => _QXZ("Number changed."), -23 => _QXZ("Redirection to new destination."), -25 => _QXZ("Exchange routing error."), -27 => _QXZ("Destination out of order."), -28 => _QXZ("Invalid number format (address incomplete)."), -29 => _QXZ("Facilities rejected."), -30 => _QXZ("Response to STATUS INQUIRY."), -31 => _QXZ("Normal, unspecified."), -34 => _QXZ("No circuit/channel available."), -38 => _QXZ("Network out of order."), -41 => _QXZ("Temporary failure."), -42 => _QXZ("Switching equipment congestion."), -43 => _QXZ("Access information discarded."), -44 => _QXZ("Requested circuit/channel not available."), -50 => _QXZ("Requested facility not subscribed."), -52 => _QXZ("Outgoing calls barred."), -54 => _QXZ("Incoming calls barred."), -57 => _QXZ("Bearer capability not authorized."), -58 => _QXZ("Bearer capability not presently available."), -63 => _QXZ("Service or option not available, unspecified."), -65 => _QXZ("Bearer capability not implemented."), -66 => _QXZ("Channel type not implemented."), -69 => _QXZ("Requested facility not implemented."), -79 => _QXZ("Service or option not implemented, unspecified."), -81 => _QXZ("Invalid call reference value."), -88 => _QXZ("Incompatible destination."), -95 => _QXZ("Invalid message, unspecified."), -96 => _QXZ("Mandatory information element is missing."), -97 => _QXZ("Message type non-existent or not implemented."), -98 => _QXZ("Message not compatible with call state or message type non-existent or not implemented."), -99 => _QXZ("Information element / parameter non-existent or not implemented."), -100 => _QXZ("Invalid information element contents."), -101 => _QXZ("Message not compatible with call state."), -102 => _QXZ("Recovery on timer expiry."), -103 => _QXZ("Parameter non-existent or not implemented - passed on (national use)."), -111 => _QXZ("Protocol error, unspecified."), -127 => _QXZ("Interworking, unspecified.") -); - -#### SIP response code directory -$sip_response_directory = array( - 0 => "", - 100 => _QXZ("Trying"), - 180 => _QXZ("Ringing"), - 181 => _QXZ("Call is Being Forwarded"), - 182 => _QXZ("Queued"), - 183 => _QXZ("Session in Progress"), - 199 => _QXZ("Early Dialog Terminated"), - 200 => _QXZ("OK"), - 202 => _QXZ("Accepted"), - 204 => _QXZ("No Notification"), - 300 => _QXZ("Multiple Choices"), - 301 => _QXZ("Moved Permanently"), - 301 => _QXZ("Moved Temporarily"), - 302 => _QXZ("Moved Temporarily"), - 305 => _QXZ("Use Proxy"), - 380 => _QXZ("Alternative Service"), - 400 => _QXZ("Bad Request"), - 401 => _QXZ("Unauthorized"), - 402 => _QXZ("Payment Required"), - 403 => _QXZ("Forbidden"), - 404 => _QXZ("Not Found"), - 405 => _QXZ("Method Not Allowed"), - 406 => _QXZ("Not Acceptable"), - 407 => _QXZ("Proxy Authentication Required"), - 408 => _QXZ("Request Timeout"), - 409 => _QXZ("Conflict"), - 410 => _QXZ("Gone"), - 411 => _QXZ("Length Required"), - 412 => _QXZ("Conditional Request Failed"), - 413 => _QXZ("Request Entity Too Large"), - 414 => _QXZ("Request-URI Too Long"), - 415 => _QXZ("Unsupported Media Type"), - 416 => _QXZ("Unsupported URI Scheme"), - 417 => _QXZ("Unknown Resource-Priority"), - 420 => _QXZ("Bad Extension"), - 421 => _QXZ("Extension Required"), - 422 => _QXZ("Session Interval Too Small"), - 423 => _QXZ("Interval Too Brief"), - 424 => _QXZ("Bad Location Information"), - 428 => _QXZ("Use Identity Header"), - 429 => _QXZ("Provide Referrer Identity"), - 430 => _QXZ("Flow Failed"), - 433 => _QXZ("Anonymity Disallowed"), - 436 => _QXZ("Bad Identity-Info"), - 437 => _QXZ("Unsupported Certificate"), - 438 => _QXZ("Invalid Identity Header"), - 439 => _QXZ("First Hop Lacks Outbound Support"), - 470 => _QXZ("Consent Needed"), - 480 => _QXZ("Temporarily Unavailable"), - 481 => _QXZ("Call/Transaction Does Not Exist"), - 482 => _QXZ("Loop Detected."), - 483 => _QXZ("Too Many Hops"), - 484 => _QXZ("Address Incomplete"), - 485 => _QXZ("Ambiguous"), - 486 => _QXZ("Busy Here"), - 487 => _QXZ("Request Terminated"), - 488 => _QXZ("Not Acceptable Here"), - 489 => _QXZ("Bad Event"), - 491 => _QXZ("Request Pending"), - 493 => _QXZ("Undecipherable"), - 494 => _QXZ("Security Agreement Required"), - 500 => _QXZ("Server Internal Error"), - 501 => _QXZ("Not Implemented"), - 502 => _QXZ("Bad Gateway"), - 503 => _QXZ("Service Unavailable"), - 504 => _QXZ("Server Time-out"), - 505 => _QXZ("Version Not Supported"), - 513 => _QXZ("Message Too Large"), - 580 => _QXZ("Precondition Failure"), - 600 => _QXZ("Busy Everywhere"), - 603 => _QXZ("Decline"), - 604 => _QXZ("Does Not Exist Anywhere"), - 606 => _QXZ("Not Acceptable"), -); - -$master_hangup_cause_array=array(); -$i=0; -#while (list($key, $val)=each($hangup_cause_dictionary)) { -foreach($hangup_cause_dictionary as $key => $val) { - $master_hangup_cause_array[$i]=$key; - $i++; -} - -$master_sip_response_directory=array(); -$master_sip_response_verbiage_directory=array(); -$i=0; -#while (list($key, $val)=each($sip_response_directory)) { -foreach($sip_response_directory as $key => $val) { - $master_sip_response_directory[$i]=$key; - $master_sip_response_verbiage_directory[$i]=$val; - $i++; -} - -$hangup_causes_to_print=count($master_hangup_cause_array); -$sip_responses_to_print=count($master_sip_response_directory); -$master_dialstatus_array=array(_QXZ("ANSWER"), _QXZ("BUSY"), _QXZ("NOANSWER"), _QXZ("CANCEL"), _QXZ("CONGESTION"), _QXZ("CHANUNAVAIL"), _QXZ("DONTCALL"), _QXZ("TORTURE"), _QXZ("INVALIDARGS")); -$dialstatuses_to_print=count($master_dialstatus_array); - - -if ($non_latin < 1) - { - $PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER); - $PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW); - } -else - { - $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); - $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); - } - -$stmt="SELECT selected_language from vicidial_users where user='$PHP_AUTH_USER';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$sl_ct = mysqli_num_rows($rslt); -if ($sl_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $VUselected_language = $row[0]; - } - -$auth=0; -$reports_auth=0; -$admin_auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth > 0) - { - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $admin_auth=$row[0]; - - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $reports_auth=$row[0]; - - if ($reports_auth < 1) - { - $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ( ($reports_auth > 0) and ($admin_auth < 1) ) - { - $ADD=999999; - $reports_only_user=1; - } - } -else - { - $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ($auth_message == 'IPBLOCK') - { - $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - - -##### BEGIN log visit to the vicidial_report_log table ##### -$LOGip = getenv("REMOTE_ADDR"); -$LOGbrowser = getenv("HTTP_USER_AGENT"); -$LOGscript_name = getenv("SCRIPT_NAME"); -$LOGserver_name = getenv("SERVER_NAME"); -$LOGserver_port = getenv("SERVER_PORT"); -$LOGrequest_uri = getenv("REQUEST_URI"); -$LOGhttp_referer = getenv("HTTP_REFERER"); -$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); -$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); -$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); -if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} -else {$LOGserver_port = ":$LOGserver_port";} -$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; - -$LOGhostname = php_uname('n'); -if (strlen($LOGhostname)<1) {$LOGhostname='X';} -if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} - -$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$webserver_id_ct = mysqli_num_rows($rslt); -if ($webserver_id_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $webserver_id = $row[0]; - } -else - { - ##### insert webserver entry - $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $affected_rows = mysqli_affected_rows($link); - $webserver_id = mysqli_insert_id($link); - } - -$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name', url='$LOGfull_url', webserver='$webserver_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$report_log_id = mysqli_insert_id($link); -##### END log visit to the vicidial_report_log table ##### - -if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) - { - mysqli_close($link); - $use_slave_server=1; - $db_source = 'S'; - require("dbconnect_mysqli.php"); - $MAIN.="\n"; - } - -if (strlen($query_date_D) < 6) {$query_date_D = "00:00:00";} -if (strlen($query_date_T) < 6) {$query_date_T = "23:59:59";} -$NOW_DATE = date("Y-m-d"); -if (!isset($server_ip)) {$server_ip = array();} -if (!isset($hangup_cause)) {$hangup_cause = array();} -if (!isset($dial_status)) {$dial_status = array();} -if (!isset($sip_hangup_cause)) {$sip_hangup_cause = array();} -if (!isset($query_date)) {$query_date = $NOW_DATE;} - -$server_ip_string='|'; -$server_ip_ct = count($server_ip); -$i=0; -while($i < $server_ip_ct) - { - $server_ip_string .= "$server_ip[$i]|"; - $i++; - } - -$server_stmt="SELECT server_ip,server_description from servers where active_asterisk_server='Y' order by server_ip asc"; -if ($DB) {echo "|$server_stmt|\n";} -$server_rslt=mysql_to_mysqli($server_stmt, $link); -$servers_to_print=mysqli_num_rows($server_rslt); -$i=0; -$LISTserverIPs=array(); -$LISTserver_names=array(); -while ($i < $servers_to_print) - { - $row=mysqli_fetch_row($server_rslt); - $LISTserverIPs[$i] = $row[0]; - $LISTserver_names[$i] = $row[1]; - if (preg_match('/\-ALL/',$server_ip_string) ) - { - $server_ip[$i] = $LISTserverIPs[$i]; - } - $i++; - } - -$i=0; -$server_ips_string='|'; -$server_ip_ct = count($server_ip); -while($i < $server_ip_ct) - { - if ( (strlen($server_ip[$i]) > 0) and (preg_match("/\|$server_ip[$i]\|/",$server_ip_string)) ) - { - $server_ips_string .= "$server_ip[$i]|"; - $server_ip_SQL .= "'$server_ip[$i]',"; - $server_ipQS .= "&server_ip[]=$server_ip[$i]"; - } - $i++; - } - -if ( (preg_match('/\-\-ALL\-\-/',$server_ip_string) ) or ($server_ip_ct < 1) ) - { - $server_ip_SQL = ""; - $server_rpt_string="- ALL servers "; - if (preg_match('/\-\-ALL\-\-/',$server_ip_string)) {$server_ipQS="&server_ip[]=--ALL--";} - } -else - { - $server_ip_SQL = preg_replace('/,$/i', '',$server_ip_SQL); - $server_ip_SQL = "and server_ip IN($server_ip_SQL)"; - $server_rpt_string="- server(s) ".preg_replace('/\|/', ", ", substr($server_ip_string, 1, -1)); - } -if (strlen($server_ip_SQL)<3) {$server_ip_SQL="";} - -########### HANGUP CAUSES -$hangup_cause_string='|'; -$dialstatus_string='|'; -$sip_hangup_cause_string='|'; - -$hangup_cause_ct = count($hangup_cause); -$dial_status_ct = count($dial_status); -$sip_hangup_cause_ct = count($sip_hangup_cause); - -$i=0; -while($i < $hangup_cause_ct) - { - $hangup_cause_string .= "$hangup_cause[$i]|"; - $i++; - } - -$j=0; -while($j < $dial_status_ct) - { - $dialstatus_string .= "$dial_status[$j]|"; - $j++; - } - -$i=0; -while($i < $sip_hangup_cause_ct) - { - $sip_hangup_cause_string .= "$sip_hangup_cause[$i]|"; - $i++; - } - -$i=0; $j=0; -$hangup_causes_string='|'; -$dialstatuses_string='|'; -$sip_hangup_causes_string='|'; -while($i < $hangup_cause_ct) - { - if ( (strlen($hangup_cause[$i]) > 0) and (preg_match("/\|$hangup_cause[$i]\|/",$hangup_cause_string)) ) - { - $hangup_causes_string .= "$hangup_cause[$i]|"; - $hangup_causeQS .= "&hangup_cause[]=$hangup_cause[$i]"; - } - $i++; - } - -$i=0; -$sip_hangup_cause_SQL=""; -while($i < $sip_hangup_cause_ct) - { - if ( (strlen($sip_hangup_cause[$i]) > 0) and (preg_match("/\|$sip_hangup_cause[$i]\|/",$sip_hangup_cause_string)) ) - { - $sip_hangup_causes_string .= "$sip_hangup_cause[$i]|"; - $sip_hangup_causeQS .= "&sip_hangup_cause[]=$sip_hangup_cause[$i]"; - $sip_hangup_cause_SQL.="$sip_hangup_cause[$i],"; - } - $i++; - } - -while ($j < $dial_status_ct) - { - if ( (strlen($dial_status[$j]) > 0) and (preg_match("/\|$dial_status[$j]\|/",$dialstatus_string)) ) - { - $dialstatuses_string .= "$dial_status[$j]|"; - $dial_statusQS .= "&dial_status[]=$dial_status[$j]"; - } - $j++; - } - -$i=0; -while($i < $hangup_cause_ct) - { - $j=0; - while ($j < $dial_status_ct) - { - if ( (strlen($hangup_cause[$i]) > 0) and (preg_match("/\|$hangup_cause[$i]\|/",$hangup_cause_string)) and (strlen($dial_status[$j]) > 0) and (preg_match("/\|$dial_status[$j]\|/",$dialstatus_string)) ) - { - if ( preg_match('/\-\-ALL\-\-/',$hangup_cause_string) ) {$HC_subclause="";} else {$HC_subclause="hangup_cause='$hangup_cause[$i]'";} - if ( preg_match('/\-\-ALL\-\-/',$dialstatus_string) ) {$DS_subclause="";} else {$DS_subclause="dialstatus='$dial_status[$j]'";} - if ($HC_subclause=="" || $DS_subclause=="") {$conjunction="";} else {$conjunction=" and ";} - $hangup_cause_SQL .= "($HC_subclause$conjunction$DS_subclause) OR"; - $hangup_cause_SQL=preg_replace('/\(\) OR$/', '', $hangup_cause_SQL); - #$hangup_cause_SQL .= "(hangup_cause='$hangup_cause[$i]' and dialstatus='$dial_status[$j]') OR"; - } - $j++; - } - $i++; - } - -if ( (preg_match('/\-\-ALL\-\-/',$hangup_cause_string) ) or ($hangup_cause_ct < 1) ) - { - $HC_rpt_string="- "._QXZ("ALL hangup causes")." "; - if (preg_match('/\-\-ALL\-\-/',$hangup_cause_string)) {$hangup_causeQS="&hangup_cause[]=--ALL--";} - } -else - { - $hangup_causes_string=preg_replace('/\!/', "-", $hangup_causes_string); - $HC_rpt_string="AND hangup cause(s) ".preg_replace('/\|/', ", ", substr($hangup_causes_string, 1, -1)); - } - - -if ( (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string) ) or ($sip_hangup_cause_ct < 1) ) - { - $HC_rpt_string="- "._QXZ("ALL SIP hangup causes")." "; - if (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string)) - { - $sip_hangup_causeQS="&sip_hangup_cause[]=--ALL--"; - $sip_hangup_cause_SQL=""; - } - } -else - { - $sip_hangup_causes_string=preg_replace('/\!/', "-", $sip_hangup_causes_string); - $HC_rpt_string=_QXZ("AND SIP hangup cause(s)")." ".preg_replace('/\|/', ", ", substr($sip_hangup_causes_string, 1, -1)); - } -$sip_hangup_cause_SQL = preg_replace('/,$/i', '',$sip_hangup_cause_SQL); -if (strlen($sip_hangup_cause_SQL)>0) {$sip_hangup_cause_SQL="and sip_hangup_cause in ($sip_hangup_cause_SQL)";} - - -if ( (preg_match('/\-\-ALL\-\-/',$dial_status_string) ) or ($dial_status_ct < 1) ) - { - $dial_status_SQL = ""; - $DS_rpt_string="- "._QXZ("ALL dial statuses")." "; - if (preg_match('/\-\-ALL\-\-/',$dial_status_string)) {$dial_statusQS="&dial_status[]=--ALL--";} - } -else - { - #$hangup_cause_SQL=preg_replace('/ OR$/', '', $hangup_cause_SQL); - #$hangup_cause_SQL = preg_replace('/,$/i', '',$hangup_cause_SQL); - #$hangup_cause_SQL = "and ($hangup_cause_SQL)"; - $dialstatuses_string=preg_replace('/\!/', "-", $dialstatuses_string); - $DS_rpt_string="AND dial status(es) ".preg_replace('/\|/', ", ", substr($dialstatuses_string, 1, -1)); - } -$hangup_cause_SQL=preg_replace('/ OR$/', '', $hangup_cause_SQL); -$hangup_cause_SQL = preg_replace('/,$/i', '',$hangup_cause_SQL); -$hangup_cause_SQL = "and ($hangup_cause_SQL)"; - -require("screen_colors.php"); - -if (strlen($hangup_cause_SQL)<7) {$hangup_cause_SQL="";} - -######################## -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.=""._QXZ("$report_name")."\n"; - -$short_header=1; - -$MAIN.="
"; -$MAIN.="\n"; -$MAIN.=""; - -$MAIN.=""; - -$MAIN.=""; - -$MAIN.=""; - - -$MAIN.="
\n"; -$MAIN.="\n"; -$MAIN.=_QXZ("Date").":\n"; -$MAIN.=""; -$MAIN.="\n"; - -$MAIN.="

"; - -$MAIN.="
"._QXZ("to")."
"; - -$MAIN.="
"._QXZ("Server IP").":
\n"; -$MAIN.="
"._QXZ("Hangup Cause").":
"; -$MAIN.=""; -$MAIN.="
"._QXZ("Dial status").":
"; -$MAIN.=""; -$MAIN.="
"._QXZ("SIP Response").":
"; -$MAIN.=""; -$MAIN.="
\n"; -$MAIN.=_QXZ("Display as:")."
"; -$MAIN.="\n

"; -$MAIN.="

\n"; -$MAIN.="
\n"; -if ($SUBMIT && $server_ip_ct>0) { - $stmt="SELECT hangup_cause, dialstatus, count(*) as ct From vicidial_carrier_log where call_date>='$query_date $query_date_D' and call_date<='$query_date $query_date_T' $server_ip_SQL $hangup_cause_SQL group by hangup_cause, dialstatus order by hangup_cause, dialstatus"; - $rslt=mysql_to_mysqli($stmt, $link); - $TEXT.="
\n";
-	if ($DB) {$TEXT.=$stmt."\n";}
-	if (mysqli_num_rows($rslt)>0) {
-		$TEXT.="--- "._QXZ("DIAL STATUS BREAKDOWN FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string\n";
-		$TEXT.="+--------------+-------------+---------+\n";
-		$TEXT.="| "._QXZ("HANGUP CAUSE",12)." | "._QXZ("DIAL STATUS",11)." |  "._QXZ("COUNT",6)." |\n";
-		$TEXT.="+--------------+-------------+---------+\n";
-
-		$HTML.="
"; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - - $total_count=0; - while ($row=mysqli_fetch_array($rslt)) { - $TEXT.="| ".sprintf("%-13s", $row["hangup_cause"]); - $TEXT.="| ".sprintf("%-12s", $row["dialstatus"]); - $TEXT.="| ".sprintf("%-8s", $row["ct"]); - $TEXT.="|\n"; - $total_count+=$row["ct"]; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - } - $TEXT.="+--------------+-------------+---------+\n"; - $TEXT.="| "._QXZ("TOTAL",26,"r")." | ".sprintf("%-8s", $total_count)."|\n"; - $TEXT.="+--------------+-------------+---------+\n\n\n"; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="
"._QXZ("DIAL STATUS BREAKDOWN FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string
"._QXZ("HANGUP CAUSE").""._QXZ("DIAL STATUS").""._QXZ("COUNT")."
".$row["hangup_cause"]."".$row["dialstatus"]."".$row["ct"]."
"._QXZ("TOTAL")."".$total_count."


\n"; - - $rpt_stmt="SELECT vicidial_carrier_log.*, vicidial_log.phone_number from vicidial_carrier_log left join vicidial_log on vicidial_log.uniqueid=vicidial_carrier_log.uniqueid where vicidial_carrier_log.call_date>='$query_date $query_date_D' and vicidial_carrier_log.call_date<='$query_date $query_date_T' $server_ip_SQL $hangup_cause_SQL $sip_hangup_cause_SQL order by vicidial_carrier_log.call_date asc"; - $rpt_rslt=mysql_to_mysqli($rpt_stmt, $link); - if ($DB) {$TEXT.=$rpt_stmt."\n";} - - if (!$lower_limit) {$lower_limit=1;} - if ($lower_limit+999>=mysqli_num_rows($rpt_rslt)) {$upper_limit=($lower_limit+mysqli_num_rows($rpt_rslt)%1000)-1;} else {$upper_limit=$lower_limit+999;} - - $TEXT.="--- "._QXZ("CARRIER LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string, $DS_rpt_string\n --- "._QXZ("RECORDS")." #$lower_limit-$upper_limit ["._QXZ("DOWNLOAD")."]\n"; - $carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+--------------+-----------+---------------+--------------+--------------+--------------------------------+\n"; - $carrier_rpt.="| "._QXZ("UNIQUE ID",20)." | "._QXZ("CALL DATE",19)." | "._QXZ("SERVER IP",15)." | "._QXZ("LEAD ID",9)." | "._QXZ("HANGUP CAUSE",12)." | "._QXZ("DIAL STATUS",11)." | "._QXZ("CHANNEL",40)." | "._QXZ("CALLER ID",12)." | "._QXZ("DIAL TIME",9)." | "._QXZ("ANSWERED TIME",13)." | "._QXZ("PHONE NUMBER",12)." | "._QXZ("SIP RESPONSE",12)." | "._QXZ("SIP REASON",30)." |\n"; - $carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+--------------+-----------+---------------+--------------+--------------+--------------------------------+\n"; - $CSV_text="\""._QXZ("UNIQUE ID")."\",\""._QXZ("CALL DATE")."\",\""._QXZ("SERVER IP")."\",\""._QXZ("LEAD ID")."\",\""._QXZ("HANGUP CAUSE")."\",\""._QXZ("DIAL STATUS")."\",\""._QXZ("CHANNEL")."\",\""._QXZ("CALLER ID")."\",\""._QXZ("DIAL TIME")."\",\""._QXZ("ANSWERED TIME")."\",\""._QXZ("PHONE NUMBER")."\",\""._QXZ("SIP RESPONSE")."\",\""._QXZ("SIP REASON")."\"\n"; - - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - - for ($i=1; $i<=mysqli_num_rows($rpt_rslt); $i++) { - $row=mysqli_fetch_array($rpt_rslt); - $phone_number=""; $phone_note=""; - - if (strlen($row["phone_number"])==0) { - $stmt2="SELECT phone_number, alt_phone, address3 from vicidial_list where lead_id='$row[lead_id]'"; - $rslt2=mysql_to_mysqli($stmt2, $link); - $channel=$row["channel"]; - while ($row2=mysqli_fetch_array($rslt2)) { - if (strlen($row2["alt_phone"])>=7 && preg_match("/$row2[alt_phone]/", $channel)) {$phone_number=$row2["alt_phone"]; $phone_note="ALT";} - else if (strlen($row2["address3"])>=7 && preg_match("/$row2[address3]/", $channel)) {$phone_number=$row2["address3"]; $phone_note="ADDR3";} - else if (strlen($row2["phone_number"])>=7 && preg_match("/$row2[phone_number]/", $channel)) {$phone_number=$row2["phone_number"]; $phone_note="*";} - } - } else { - $phone_number=$row["phone_number"]; - } - - $caller_id=""; - $log_stmt="select outbound_cid from vicidial_dial_log where lead_id='$row[lead_id]' and caller_code='$row[caller_code]'"; - # and call_date>='$row[call_date]'-INTERVAL 1 MINUTE and call_date<='$row[call_date]'+INTERVAL 1 MINUTE - $log_rslt=mysql_to_mysqli($log_stmt, $link); - while ($log_row=mysqli_fetch_array($log_rslt)) - { - $outbound_cid=$log_row[0]; - preg_match('/\<[0-9]{7,}\>/', $outbound_cid, $cid_info); - $caller_id=preg_replace('/[^0-9]/', '', $cid_info[0]); - } - - $CSV_text.="\"$row[uniqueid]\",\"$row[call_date]\",\"$row[server_ip]\",\"$row[lead_id]\",\"$row[hangup_cause]\",\"$row[dialstatus]\",\"$row[channel]\",\"$caller_id\",\"$row[dial_time]\",\"$row[answered_time]\",\"$phone_number\",\"$row[sip_hangup_cause]\",\"$row[sip_hangup_reason]\"\n"; - if ($i>=$lower_limit && $i<=$upper_limit) { - if (strlen($row["channel"])>37) {$row["channel"]=substr($row["channel"],0,37)."...";} - $carrier_rpt.="| ".sprintf("%-21s", $row["uniqueid"]); - $carrier_rpt.="| ".sprintf("%-20s", $row["call_date"]); - $carrier_rpt.="| ".sprintf("%-16s", $row["server_ip"]); - $carrier_rpt.="| ".sprintf("%-10s", $row["lead_id"]); - $carrier_rpt.="| ".sprintf("%-13s", $row["hangup_cause"]); - $carrier_rpt.="| ".sprintf("%-12s", $row["dialstatus"]); - $carrier_rpt.="| ".sprintf("%-41s", $row["channel"]); - $carrier_rpt.="| ".sprintf("%-13s", $caller_id); - $carrier_rpt.="| ".sprintf("%-10s", $row["dial_time"]); - $carrier_rpt.="| ".sprintf("%-14s", $row["answered_time"]); - $carrier_rpt.="| ".sprintf("%-13s", $phone_number); - $carrier_rpt.="| ".sprintf("%-13s", $row["sip_hangup_cause"]); - $carrier_rpt.="| ".sprintf("%-31s", $row["sip_hangup_reason"])."|\n"; - - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.=""; - $HTML.="\n"; - } - } - $carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+--------------+-----------+---------------+--------------+--------------+--------------------------------+\n"; - - $carrier_rpt_hf=""; - $ll=$lower_limit-1000; - $HTML.=""; - if ($ll>=1) { - $carrier_rpt_hf.="[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."]"; - $HTML.=""; - } - $carrier_rpt_hf.=sprintf("%-145s", " "); - if (($lower_limit+1000)=mysqli_num_rows($rpt_rslt)) {$max_limit=mysqli_num_rows($rpt_rslt)-$upper_limit;} else {$max_limit=1000;} - $carrier_rpt_hf.="["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; - $HTML.=""; - } - $carrier_rpt_hf.="\n"; - $TEXT.=$carrier_rpt_hf.$carrier_rpt.$carrier_rpt_hf; - $HTML.="
"._QXZ("CARRIER LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string, $DS_rpt_string\n --- "._QXZ("RECORDS")." #$lower_limit-$upper_limit["._QXZ("DOWNLOAD")."]
"._QXZ("UNIQUE ID").""._QXZ("CALL DATE").""._QXZ("SERVER IP").""._QXZ("LEAD ID").""._QXZ("HANGUP CAUSE").""._QXZ("DIAL STATUS").""._QXZ("CHANNEL").""._QXZ("CALLER ID").""._QXZ("DIAL TIME").""._QXZ("ANSWERED TIME").""._QXZ("PHONE NUMBER").""._QXZ("SIP RESPONSE").""._QXZ("SIP REASON")."
".$row["uniqueid"]."".$row["call_date"]."".$row["server_ip"]."".$row["lead_id"]."".$row["hangup_cause"]."".$row["dialstatus"]."".$row["channel"]."".$caller_id."".$row["dial_time"]."".$row["answered_time"]."".$phone_number."".$row["sip_hangup_cause"]."".$row["sip_hangup_reason"]."
[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."]"; - } else { - $carrier_rpt_hf.=sprintf("%-23s", " "); - $HTML.=" ["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; - } else { - $carrier_rpt_hf.=sprintf("%23s", " "); - $HTML.=" 
"; - - } else { - $TEXT.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; - $HTML.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; - } - $TEXT.="
\n"; - - if ($report_display_type=="HTML") { - $MAIN.=$HTML; - } else { - $MAIN.=$TEXT; - } - - $MAIN.="\n"; - - -} - if ($file_download>0) { - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "AST_hangup_cause_report_$US$FILE_TIME.csv"; - $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); - $CSV_text=preg_replace('/\" +/', '"', $CSV_text); - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - - // It will be called LIST_101_20090209-121212.txt - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - - } else { - echo $HEADER; - require("admin_header.php"); - echo $MAIN; - } - -if ($db_source == 'S') - { - mysqli_close($link); - $use_slave_server=0; - $db_source = 'M'; - require("dbconnect_mysqli.php"); - } - -$endMS = microtime(); -$startMSary = explode(" ",$startMS); -$endMSary = explode(" ",$endMS); -$runS = ($endMSary[0] - $startMSary[0]); -$runM = ($endMSary[1] - $startMSary[1]); -$TOTALrun = ($runS + $runM); - -$END_TIME=date("U"); - -#print "Total run time: ".($END_TIME-$START_TIME); - -$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); - -exit; - -?> + LICENSE: AGPLv2 +# +# CHANGES +# 120331-2301 - First build +# 130413-2348 - Added report logging +# 130419-2047 - Changed how menu lists are generated to speed up initial form load +# 132305-2305 - Finalized changing of all ereg instances to preg +# 130621-0749 - Added filtering of input to prevent SQL injection attacks and new user auth +# 130902-0731 - Changed to mysqli PHP functions +# 140108-0739 - Added webserver and hostname to report logging +# 140403-1830 - Fixed SIP hangup bug +# 141114-0837 - Finalized adding QXZ translation to all admin files +# 141230-1457 - Added code for on-the-fly language translations display +# 170409-1534 - Added IP List validation code +# 170818-2345 - Added HTML formatting +# 170829-0040 - Added screen color settings +# 191013-0858 - Fixes for PHP7 +# 201218-1700 - Modified to include caller ID in results +# + +$startMS = microtime(); + +$report_name='Hangup Cause Report'; + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} + elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} +if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} + elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} +if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} + elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} +if (isset($_GET["hangup_cause"])) {$hangup_cause=$_GET["hangup_cause"];} + elseif (isset($_POST["hangup_cause"])) {$hangup_cause=$_POST["hangup_cause"];} +if (isset($_GET["sip_hangup_cause"])) {$sip_hangup_cause=$_GET["sip_hangup_cause"];} + elseif (isset($_POST["sip_hangup_cause"])) {$sip_hangup_cause=$_POST["sip_hangup_cause"];} +if (isset($_GET["dial_status"])) {$dial_status=$_GET["dial_status"];} + elseif (isset($_POST["dial_status"])) {$dial_status=$_POST["dial_status"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["lower_limit"])) {$lower_limit=$_GET["lower_limit"];} + elseif (isset($_POST["lower_limit"])) {$lower_limit=$_POST["lower_limit"];} +if (isset($_GET["upper_limit"])) {$upper_limit=$_GET["upper_limit"];} + elseif (isset($_POST["upper_limit"])) {$upper_limit=$_POST["upper_limit"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} + elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} + +$START_TIME=date("U"); + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$MAIN.="$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $SSenable_languages = $row[4]; + $SSlanguage_method = $row[5]; + } +##### END SETTINGS LOOKUP ##### +########################################### + +##### Hangup Cause Dictionary ##### +$hangup_cause_dictionary = array( +0 => _QXZ("Unspecified. No other cause codes applicable."), +1 => _QXZ("Unallocated (unassigned) number."), +2 => _QXZ("No route to specified transit network (national use)."), +3 => _QXZ("No route to destination."), +6 => _QXZ("Channel unacceptable."), +7 => _QXZ("Call awarded, being delivered in an established channel."), +16 => _QXZ("Normal call clearing."), +17 => _QXZ("User busy."), +18 => _QXZ("No user responding."), +19 => _QXZ("No answer from user (user alerted)."), +20 => _QXZ("Subscriber absent."), +21 => _QXZ("Call rejected."), +22 => _QXZ("Number changed."), +23 => _QXZ("Redirection to new destination."), +25 => _QXZ("Exchange routing error."), +27 => _QXZ("Destination out of order."), +28 => _QXZ("Invalid number format (address incomplete)."), +29 => _QXZ("Facilities rejected."), +30 => _QXZ("Response to STATUS INQUIRY."), +31 => _QXZ("Normal, unspecified."), +34 => _QXZ("No circuit/channel available."), +38 => _QXZ("Network out of order."), +41 => _QXZ("Temporary failure."), +42 => _QXZ("Switching equipment congestion."), +43 => _QXZ("Access information discarded."), +44 => _QXZ("Requested circuit/channel not available."), +50 => _QXZ("Requested facility not subscribed."), +52 => _QXZ("Outgoing calls barred."), +54 => _QXZ("Incoming calls barred."), +57 => _QXZ("Bearer capability not authorized."), +58 => _QXZ("Bearer capability not presently available."), +63 => _QXZ("Service or option not available, unspecified."), +65 => _QXZ("Bearer capability not implemented."), +66 => _QXZ("Channel type not implemented."), +69 => _QXZ("Requested facility not implemented."), +79 => _QXZ("Service or option not implemented, unspecified."), +81 => _QXZ("Invalid call reference value."), +88 => _QXZ("Incompatible destination."), +95 => _QXZ("Invalid message, unspecified."), +96 => _QXZ("Mandatory information element is missing."), +97 => _QXZ("Message type non-existent or not implemented."), +98 => _QXZ("Message not compatible with call state or message type non-existent or not implemented."), +99 => _QXZ("Information element / parameter non-existent or not implemented."), +100 => _QXZ("Invalid information element contents."), +101 => _QXZ("Message not compatible with call state."), +102 => _QXZ("Recovery on timer expiry."), +103 => _QXZ("Parameter non-existent or not implemented - passed on (national use)."), +111 => _QXZ("Protocol error, unspecified."), +127 => _QXZ("Interworking, unspecified.") +); + +#### SIP response code directory +$sip_response_directory = array( + 0 => "", + 100 => _QXZ("Trying"), + 180 => _QXZ("Ringing"), + 181 => _QXZ("Call is Being Forwarded"), + 182 => _QXZ("Queued"), + 183 => _QXZ("Session in Progress"), + 199 => _QXZ("Early Dialog Terminated"), + 200 => _QXZ("OK"), + 202 => _QXZ("Accepted"), + 204 => _QXZ("No Notification"), + 300 => _QXZ("Multiple Choices"), + 301 => _QXZ("Moved Permanently"), + 301 => _QXZ("Moved Temporarily"), + 302 => _QXZ("Moved Temporarily"), + 305 => _QXZ("Use Proxy"), + 380 => _QXZ("Alternative Service"), + 400 => _QXZ("Bad Request"), + 401 => _QXZ("Unauthorized"), + 402 => _QXZ("Payment Required"), + 403 => _QXZ("Forbidden"), + 404 => _QXZ("Not Found"), + 405 => _QXZ("Method Not Allowed"), + 406 => _QXZ("Not Acceptable"), + 407 => _QXZ("Proxy Authentication Required"), + 408 => _QXZ("Request Timeout"), + 409 => _QXZ("Conflict"), + 410 => _QXZ("Gone"), + 411 => _QXZ("Length Required"), + 412 => _QXZ("Conditional Request Failed"), + 413 => _QXZ("Request Entity Too Large"), + 414 => _QXZ("Request-URI Too Long"), + 415 => _QXZ("Unsupported Media Type"), + 416 => _QXZ("Unsupported URI Scheme"), + 417 => _QXZ("Unknown Resource-Priority"), + 420 => _QXZ("Bad Extension"), + 421 => _QXZ("Extension Required"), + 422 => _QXZ("Session Interval Too Small"), + 423 => _QXZ("Interval Too Brief"), + 424 => _QXZ("Bad Location Information"), + 428 => _QXZ("Use Identity Header"), + 429 => _QXZ("Provide Referrer Identity"), + 430 => _QXZ("Flow Failed"), + 433 => _QXZ("Anonymity Disallowed"), + 436 => _QXZ("Bad Identity-Info"), + 437 => _QXZ("Unsupported Certificate"), + 438 => _QXZ("Invalid Identity Header"), + 439 => _QXZ("First Hop Lacks Outbound Support"), + 470 => _QXZ("Consent Needed"), + 480 => _QXZ("Temporarily Unavailable"), + 481 => _QXZ("Call/Transaction Does Not Exist"), + 482 => _QXZ("Loop Detected."), + 483 => _QXZ("Too Many Hops"), + 484 => _QXZ("Address Incomplete"), + 485 => _QXZ("Ambiguous"), + 486 => _QXZ("Busy Here"), + 487 => _QXZ("Request Terminated"), + 488 => _QXZ("Not Acceptable Here"), + 489 => _QXZ("Bad Event"), + 491 => _QXZ("Request Pending"), + 493 => _QXZ("Undecipherable"), + 494 => _QXZ("Security Agreement Required"), + 500 => _QXZ("Server Internal Error"), + 501 => _QXZ("Not Implemented"), + 502 => _QXZ("Bad Gateway"), + 503 => _QXZ("Service Unavailable"), + 504 => _QXZ("Server Time-out"), + 505 => _QXZ("Version Not Supported"), + 513 => _QXZ("Message Too Large"), + 580 => _QXZ("Precondition Failure"), + 600 => _QXZ("Busy Everywhere"), + 603 => _QXZ("Decline"), + 604 => _QXZ("Does Not Exist Anywhere"), + 606 => _QXZ("Not Acceptable"), +); + +$master_hangup_cause_array=array(); +$i=0; +#while (list($key, $val)=each($hangup_cause_dictionary)) { +foreach($hangup_cause_dictionary as $key => $val) { + $master_hangup_cause_array[$i]=$key; + $i++; +} + +$master_sip_response_directory=array(); +$master_sip_response_verbiage_directory=array(); +$i=0; +#while (list($key, $val)=each($sip_response_directory)) { +foreach($sip_response_directory as $key => $val) { + $master_sip_response_directory[$i]=$key; + $master_sip_response_verbiage_directory[$i]=$val; + $i++; +} + +$hangup_causes_to_print=count($master_hangup_cause_array); +$sip_responses_to_print=count($master_sip_response_directory); +$master_dialstatus_array=array(_QXZ("ANSWER"), _QXZ("BUSY"), _QXZ("NOANSWER"), _QXZ("CANCEL"), _QXZ("CONGESTION"), _QXZ("CHANUNAVAIL"), _QXZ("DONTCALL"), _QXZ("TORTURE"), _QXZ("INVALIDARGS")); +$dialstatuses_to_print=count($master_dialstatus_array); + + +if ($non_latin < 1) + { + $PHP_AUTH_USER = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_USER); + $PHP_AUTH_PW = preg_replace('/[^-_0-9a-zA-Z]/', '', $PHP_AUTH_PW); + } +else + { + $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); + $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); + } + +$stmt="SELECT selected_language from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$sl_ct = mysqli_num_rows($rslt); +if ($sl_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $VUselected_language = $row[0]; + } + +$auth=0; +$reports_auth=0; +$admin_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $admin_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + if ($reports_auth < 1) + { + $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( ($reports_auth > 0) and ($admin_auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + + +##### BEGIN log visit to the vicidial_report_log table ##### +$LOGip = getenv("REMOTE_ADDR"); +$LOGbrowser = getenv("HTTP_USER_AGENT"); +$LOGscript_name = getenv("SCRIPT_NAME"); +$LOGserver_name = getenv("SERVER_NAME"); +$LOGserver_port = getenv("SERVER_PORT"); +$LOGrequest_uri = getenv("REQUEST_URI"); +$LOGhttp_referer = getenv("HTTP_REFERER"); +$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); +$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); +$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); +if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} +else {$LOGserver_port = ":$LOGserver_port";} +$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; + +$LOGhostname = php_uname('n'); +if (strlen($LOGhostname)<1) {$LOGhostname='X';} +if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} + +$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$webserver_id_ct = mysqli_num_rows($rslt); +if ($webserver_id_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $webserver_id = $row[0]; + } +else + { + ##### insert webserver entry + $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $affected_rows = mysqli_affected_rows($link); + $webserver_id = mysqli_insert_id($link); + } + +$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name', url='$LOGfull_url', webserver='$webserver_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$report_log_id = mysqli_insert_id($link); +##### END log visit to the vicidial_report_log table ##### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysqli_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect_mysqli.php"); + $MAIN.="\n"; + } + +if (strlen($query_date_D) < 6) {$query_date_D = "00:00:00";} +if (strlen($query_date_T) < 6) {$query_date_T = "23:59:59";} +$NOW_DATE = date("Y-m-d"); +if (!isset($server_ip)) {$server_ip = array();} +if (!isset($hangup_cause)) {$hangup_cause = array();} +if (!isset($dial_status)) {$dial_status = array();} +if (!isset($sip_hangup_cause)) {$sip_hangup_cause = array();} +if (!isset($query_date)) {$query_date = $NOW_DATE;} + +$server_ip_string='|'; +$server_ip_ct = count($server_ip); +$i=0; +while($i < $server_ip_ct) + { + $server_ip_string .= "$server_ip[$i]|"; + $i++; + } + +$server_stmt="SELECT server_ip,server_description from servers where active_asterisk_server='Y' order by server_ip asc"; +if ($DB) {echo "|$server_stmt|\n";} +$server_rslt=mysql_to_mysqli($server_stmt, $link); +$servers_to_print=mysqli_num_rows($server_rslt); +$i=0; +$LISTserverIPs=array(); +$LISTserver_names=array(); +while ($i < $servers_to_print) + { + $row=mysqli_fetch_row($server_rslt); + $LISTserverIPs[$i] = $row[0]; + $LISTserver_names[$i] = $row[1]; + if (preg_match('/\-ALL/',$server_ip_string) ) + { + $server_ip[$i] = $LISTserverIPs[$i]; + } + $i++; + } + +$i=0; +$server_ips_string='|'; +$server_ip_ct = count($server_ip); +while($i < $server_ip_ct) + { + if ( (strlen($server_ip[$i]) > 0) and (preg_match("/\|$server_ip[$i]\|/",$server_ip_string)) ) + { + $server_ips_string .= "$server_ip[$i]|"; + $server_ip_SQL .= "'$server_ip[$i]',"; + $server_ipQS .= "&server_ip[]=$server_ip[$i]"; + } + $i++; + } + +if ( (preg_match('/\-\-ALL\-\-/',$server_ip_string) ) or ($server_ip_ct < 1) ) + { + $server_ip_SQL = ""; + $server_rpt_string="- ALL servers "; + if (preg_match('/\-\-ALL\-\-/',$server_ip_string)) {$server_ipQS="&server_ip[]=--ALL--";} + } +else + { + $server_ip_SQL = preg_replace('/,$/i', '',$server_ip_SQL); + $server_ip_SQL = "and server_ip IN($server_ip_SQL)"; + $server_rpt_string="- server(s) ".preg_replace('/\|/', ", ", substr($server_ip_string, 1, -1)); + } +if (strlen($server_ip_SQL)<3) {$server_ip_SQL="";} + +########### HANGUP CAUSES +$hangup_cause_string='|'; +$dialstatus_string='|'; +$sip_hangup_cause_string='|'; + +$hangup_cause_ct = count($hangup_cause); +$dial_status_ct = count($dial_status); +$sip_hangup_cause_ct = count($sip_hangup_cause); + +$i=0; +while($i < $hangup_cause_ct) + { + $hangup_cause_string .= "$hangup_cause[$i]|"; + $i++; + } + +$j=0; +while($j < $dial_status_ct) + { + $dialstatus_string .= "$dial_status[$j]|"; + $j++; + } + +$i=0; +while($i < $sip_hangup_cause_ct) + { + $sip_hangup_cause_string .= "$sip_hangup_cause[$i]|"; + $i++; + } + +$i=0; $j=0; +$hangup_causes_string='|'; +$dialstatuses_string='|'; +$sip_hangup_causes_string='|'; +while($i < $hangup_cause_ct) + { + if ( (strlen($hangup_cause[$i]) > 0) and (preg_match("/\|$hangup_cause[$i]\|/",$hangup_cause_string)) ) + { + $hangup_causes_string .= "$hangup_cause[$i]|"; + $hangup_causeQS .= "&hangup_cause[]=$hangup_cause[$i]"; + } + $i++; + } + +$i=0; +$sip_hangup_cause_SQL=""; +while($i < $sip_hangup_cause_ct) + { + if ( (strlen($sip_hangup_cause[$i]) > 0) and (preg_match("/\|$sip_hangup_cause[$i]\|/",$sip_hangup_cause_string)) ) + { + $sip_hangup_causes_string .= "$sip_hangup_cause[$i]|"; + $sip_hangup_causeQS .= "&sip_hangup_cause[]=$sip_hangup_cause[$i]"; + $sip_hangup_cause_SQL.="$sip_hangup_cause[$i],"; + } + $i++; + } + +while ($j < $dial_status_ct) + { + if ( (strlen($dial_status[$j]) > 0) and (preg_match("/\|$dial_status[$j]\|/",$dialstatus_string)) ) + { + $dialstatuses_string .= "$dial_status[$j]|"; + $dial_statusQS .= "&dial_status[]=$dial_status[$j]"; + } + $j++; + } + +$i=0; +while($i < $hangup_cause_ct) + { + $j=0; + while ($j < $dial_status_ct) + { + if ( (strlen($hangup_cause[$i]) > 0) and (preg_match("/\|$hangup_cause[$i]\|/",$hangup_cause_string)) and (strlen($dial_status[$j]) > 0) and (preg_match("/\|$dial_status[$j]\|/",$dialstatus_string)) ) + { + if ( preg_match('/\-\-ALL\-\-/',$hangup_cause_string) ) {$HC_subclause="";} else {$HC_subclause="hangup_cause='$hangup_cause[$i]'";} + if ( preg_match('/\-\-ALL\-\-/',$dialstatus_string) ) {$DS_subclause="";} else {$DS_subclause="dialstatus='$dial_status[$j]'";} + if ($HC_subclause=="" || $DS_subclause=="") {$conjunction="";} else {$conjunction=" and ";} + $hangup_cause_SQL .= "($HC_subclause$conjunction$DS_subclause) OR"; + $hangup_cause_SQL=preg_replace('/\(\) OR$/', '', $hangup_cause_SQL); + #$hangup_cause_SQL .= "(hangup_cause='$hangup_cause[$i]' and dialstatus='$dial_status[$j]') OR"; + } + $j++; + } + $i++; + } + +if ( (preg_match('/\-\-ALL\-\-/',$hangup_cause_string) ) or ($hangup_cause_ct < 1) ) + { + $HC_rpt_string="- "._QXZ("ALL hangup causes")." "; + if (preg_match('/\-\-ALL\-\-/',$hangup_cause_string)) {$hangup_causeQS="&hangup_cause[]=--ALL--";} + } +else + { + $hangup_causes_string=preg_replace('/\!/', "-", $hangup_causes_string); + $HC_rpt_string="AND hangup cause(s) ".preg_replace('/\|/', ", ", substr($hangup_causes_string, 1, -1)); + } + + +if ( (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string) ) or ($sip_hangup_cause_ct < 1) ) + { + $HC_rpt_string="- "._QXZ("ALL SIP hangup causes")." "; + if (preg_match('/\-\-ALL\-\-/',$sip_hangup_cause_string)) + { + $sip_hangup_causeQS="&sip_hangup_cause[]=--ALL--"; + $sip_hangup_cause_SQL=""; + } + } +else + { + $sip_hangup_causes_string=preg_replace('/\!/', "-", $sip_hangup_causes_string); + $HC_rpt_string=_QXZ("AND SIP hangup cause(s)")." ".preg_replace('/\|/', ", ", substr($sip_hangup_causes_string, 1, -1)); + } +$sip_hangup_cause_SQL = preg_replace('/,$/i', '',$sip_hangup_cause_SQL); +if (strlen($sip_hangup_cause_SQL)>0) {$sip_hangup_cause_SQL="and sip_hangup_cause in ($sip_hangup_cause_SQL)";} + + +if ( (preg_match('/\-\-ALL\-\-/',$dial_status_string) ) or ($dial_status_ct < 1) ) + { + $dial_status_SQL = ""; + $DS_rpt_string="- "._QXZ("ALL dial statuses")." "; + if (preg_match('/\-\-ALL\-\-/',$dial_status_string)) {$dial_statusQS="&dial_status[]=--ALL--";} + } +else + { + #$hangup_cause_SQL=preg_replace('/ OR$/', '', $hangup_cause_SQL); + #$hangup_cause_SQL = preg_replace('/,$/i', '',$hangup_cause_SQL); + #$hangup_cause_SQL = "and ($hangup_cause_SQL)"; + $dialstatuses_string=preg_replace('/\!/', "-", $dialstatuses_string); + $DS_rpt_string="AND dial status(es) ".preg_replace('/\|/', ", ", substr($dialstatuses_string, 1, -1)); + } +$hangup_cause_SQL=preg_replace('/ OR$/', '', $hangup_cause_SQL); +$hangup_cause_SQL = preg_replace('/,$/i', '',$hangup_cause_SQL); +$hangup_cause_SQL = "and ($hangup_cause_SQL)"; + +require("screen_colors.php"); + +if (strlen($hangup_cause_SQL)<7) {$hangup_cause_SQL="";} + +######################## +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.=""._QXZ("$report_name")."\n"; + +$short_header=1; + +$MAIN.="
"; +$MAIN.="
\n"; +$MAIN.=""; + +$MAIN.=""; + +$MAIN.=""; + +$MAIN.=""; + + +$MAIN.="
\n"; +$MAIN.="\n"; +$MAIN.=_QXZ("Date").":\n"; +$MAIN.=""; +$MAIN.="\n"; + +$MAIN.="

"; + +$MAIN.="
"._QXZ("to")."
"; + +$MAIN.="
"._QXZ("Server IP").":
\n"; +$MAIN.="
"._QXZ("Hangup Cause").":
"; +$MAIN.=""; +$MAIN.="
"._QXZ("Dial status").":
"; +$MAIN.=""; +$MAIN.="
"._QXZ("SIP Response").":
"; +$MAIN.=""; +$MAIN.="
\n"; +$MAIN.=_QXZ("Display as:")."
"; +$MAIN.="\n

"; +$MAIN.="

\n"; +$MAIN.="
\n"; +if ($SUBMIT && $server_ip_ct>0) { + $stmt="SELECT hangup_cause, dialstatus, count(*) as ct From vicidial_carrier_log where call_date>='$query_date $query_date_D' and call_date<='$query_date $query_date_T' $server_ip_SQL $hangup_cause_SQL group by hangup_cause, dialstatus order by hangup_cause, dialstatus"; + $rslt=mysql_to_mysqli($stmt, $link); + $TEXT.="
\n";
+	if ($DB) {$TEXT.=$stmt."\n";}
+	if (mysqli_num_rows($rslt)>0) {
+		$TEXT.="--- "._QXZ("DIAL STATUS BREAKDOWN FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string\n";
+		$TEXT.="+--------------+-------------+---------+\n";
+		$TEXT.="| "._QXZ("HANGUP CAUSE",12)." | "._QXZ("DIAL STATUS",11)." |  "._QXZ("COUNT",6)." |\n";
+		$TEXT.="+--------------+-------------+---------+\n";
+
+		$HTML.="
"; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + + $total_count=0; + while ($row=mysqli_fetch_array($rslt)) { + $TEXT.="| ".sprintf("%-13s", $row["hangup_cause"]); + $TEXT.="| ".sprintf("%-12s", $row["dialstatus"]); + $TEXT.="| ".sprintf("%-8s", $row["ct"]); + $TEXT.="|\n"; + $total_count+=$row["ct"]; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + } + $TEXT.="+--------------+-------------+---------+\n"; + $TEXT.="| "._QXZ("TOTAL",26,"r")." | ".sprintf("%-8s", $total_count)."|\n"; + $TEXT.="+--------------+-------------+---------+\n\n\n"; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="
"._QXZ("DIAL STATUS BREAKDOWN FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string
"._QXZ("HANGUP CAUSE").""._QXZ("DIAL STATUS").""._QXZ("COUNT")."
".$row["hangup_cause"]."".$row["dialstatus"]."".$row["ct"]."
"._QXZ("TOTAL")."".$total_count."


\n"; + + $rpt_stmt="SELECT vicidial_carrier_log.*, vicidial_log.phone_number from vicidial_carrier_log left join vicidial_log on vicidial_log.uniqueid=vicidial_carrier_log.uniqueid where vicidial_carrier_log.call_date>='$query_date $query_date_D' and vicidial_carrier_log.call_date<='$query_date $query_date_T' $server_ip_SQL $hangup_cause_SQL $sip_hangup_cause_SQL order by vicidial_carrier_log.call_date asc"; + $rpt_rslt=mysql_to_mysqli($rpt_stmt, $link); + if ($DB) {$TEXT.=$rpt_stmt."\n";} + + if (!$lower_limit) {$lower_limit=1;} + if ($lower_limit+999>=mysqli_num_rows($rpt_rslt)) {$upper_limit=($lower_limit+mysqli_num_rows($rpt_rslt)%1000)-1;} else {$upper_limit=$lower_limit+999;} + + $TEXT.="--- "._QXZ("CARRIER LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string, $DS_rpt_string\n --- "._QXZ("RECORDS")." #$lower_limit-$upper_limit ["._QXZ("DOWNLOAD")."]\n"; + $carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+--------------+-----------+---------------+--------------+--------------+--------------------------------+\n"; + $carrier_rpt.="| "._QXZ("UNIQUE ID",20)." | "._QXZ("CALL DATE",19)." | "._QXZ("SERVER IP",15)." | "._QXZ("LEAD ID",9)." | "._QXZ("HANGUP CAUSE",12)." | "._QXZ("DIAL STATUS",11)." | "._QXZ("CHANNEL",40)." | "._QXZ("CALLER ID",12)." | "._QXZ("DIAL TIME",9)." | "._QXZ("ANSWERED TIME",13)." | "._QXZ("PHONE NUMBER",12)." | "._QXZ("SIP RESPONSE",12)." | "._QXZ("SIP REASON",30)." |\n"; + $carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+--------------+-----------+---------------+--------------+--------------+--------------------------------+\n"; + $CSV_text="\""._QXZ("UNIQUE ID")."\",\""._QXZ("CALL DATE")."\",\""._QXZ("SERVER IP")."\",\""._QXZ("LEAD ID")."\",\""._QXZ("HANGUP CAUSE")."\",\""._QXZ("DIAL STATUS")."\",\""._QXZ("CHANNEL")."\",\""._QXZ("CALLER ID")."\",\""._QXZ("DIAL TIME")."\",\""._QXZ("ANSWERED TIME")."\",\""._QXZ("PHONE NUMBER")."\",\""._QXZ("SIP RESPONSE")."\",\""._QXZ("SIP REASON")."\"\n"; + + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + + for ($i=1; $i<=mysqli_num_rows($rpt_rslt); $i++) { + $row=mysqli_fetch_array($rpt_rslt); + $phone_number=""; $phone_note=""; + + if (strlen($row["phone_number"])==0) { + $stmt2="SELECT phone_number, alt_phone, address3 from vicidial_list where lead_id='$row[lead_id]'"; + $rslt2=mysql_to_mysqli($stmt2, $link); + $channel=$row["channel"]; + while ($row2=mysqli_fetch_array($rslt2)) { + if (strlen($row2["alt_phone"])>=7 && preg_match("/$row2[alt_phone]/", $channel)) {$phone_number=$row2["alt_phone"]; $phone_note="ALT";} + else if (strlen($row2["address3"])>=7 && preg_match("/$row2[address3]/", $channel)) {$phone_number=$row2["address3"]; $phone_note="ADDR3";} + else if (strlen($row2["phone_number"])>=7 && preg_match("/$row2[phone_number]/", $channel)) {$phone_number=$row2["phone_number"]; $phone_note="*";} + } + } else { + $phone_number=$row["phone_number"]; + } + + $caller_id=""; + $log_stmt="select outbound_cid from vicidial_dial_log where lead_id='$row[lead_id]' and caller_code='$row[caller_code]'"; + # and call_date>='$row[call_date]'-INTERVAL 1 MINUTE and call_date<='$row[call_date]'+INTERVAL 1 MINUTE + $log_rslt=mysql_to_mysqli($log_stmt, $link); + while ($log_row=mysqli_fetch_array($log_rslt)) + { + $outbound_cid=$log_row[0]; + preg_match('/\<[0-9]{7,}\>/', $outbound_cid, $cid_info); + $caller_id=preg_replace('/[^0-9]/', '', $cid_info[0]); + } + + $CSV_text.="\"$row[uniqueid]\",\"$row[call_date]\",\"$row[server_ip]\",\"$row[lead_id]\",\"$row[hangup_cause]\",\"$row[dialstatus]\",\"$row[channel]\",\"$caller_id\",\"$row[dial_time]\",\"$row[answered_time]\",\"$phone_number\",\"$row[sip_hangup_cause]\",\"$row[sip_hangup_reason]\"\n"; + if ($i>=$lower_limit && $i<=$upper_limit) { + if (strlen($row["channel"])>37) {$row["channel"]=substr($row["channel"],0,37)."...";} + $carrier_rpt.="| ".sprintf("%-21s", $row["uniqueid"]); + $carrier_rpt.="| ".sprintf("%-20s", $row["call_date"]); + $carrier_rpt.="| ".sprintf("%-16s", $row["server_ip"]); + $carrier_rpt.="| ".sprintf("%-10s", $row["lead_id"]); + $carrier_rpt.="| ".sprintf("%-13s", $row["hangup_cause"]); + $carrier_rpt.="| ".sprintf("%-12s", $row["dialstatus"]); + $carrier_rpt.="| ".sprintf("%-41s", $row["channel"]); + $carrier_rpt.="| ".sprintf("%-13s", $caller_id); + $carrier_rpt.="| ".sprintf("%-10s", $row["dial_time"]); + $carrier_rpt.="| ".sprintf("%-14s", $row["answered_time"]); + $carrier_rpt.="| ".sprintf("%-13s", $phone_number); + $carrier_rpt.="| ".sprintf("%-13s", $row["sip_hangup_cause"]); + $carrier_rpt.="| ".sprintf("%-31s", $row["sip_hangup_reason"])."|\n"; + + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.=""; + $HTML.="\n"; + } + } + $carrier_rpt.="+----------------------+---------------------+-----------------+-----------+--------------+-------------+------------------------------------------+--------------+-----------+---------------+--------------+--------------+--------------------------------+\n"; + + $carrier_rpt_hf=""; + $ll=$lower_limit-1000; + $HTML.=""; + if ($ll>=1) { + $carrier_rpt_hf.="[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."]"; + $HTML.=""; + } + $carrier_rpt_hf.=sprintf("%-145s", " "); + if (($lower_limit+1000)=mysqli_num_rows($rpt_rslt)) {$max_limit=mysqli_num_rows($rpt_rslt)-$upper_limit;} else {$max_limit=1000;} + $carrier_rpt_hf.="["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; + $HTML.=""; + } + $carrier_rpt_hf.="\n"; + $TEXT.=$carrier_rpt_hf.$carrier_rpt.$carrier_rpt_hf; + $HTML.="
"._QXZ("CARRIER LOG RECORDS FOR")." $query_date, $query_date_D "._QXZ("TO")." $query_date_T $server_rpt_string, $HC_rpt_string, $DS_rpt_string\n --- "._QXZ("RECORDS")." #$lower_limit-$upper_limit["._QXZ("DOWNLOAD")."]
"._QXZ("UNIQUE ID").""._QXZ("CALL DATE").""._QXZ("SERVER IP").""._QXZ("LEAD ID").""._QXZ("HANGUP CAUSE").""._QXZ("DIAL STATUS").""._QXZ("CHANNEL").""._QXZ("CALLER ID").""._QXZ("DIAL TIME").""._QXZ("ANSWERED TIME").""._QXZ("PHONE NUMBER").""._QXZ("SIP RESPONSE").""._QXZ("SIP REASON")."
".$row["uniqueid"]."".$row["call_date"]."".$row["server_ip"]."".$row["lead_id"]."".$row["hangup_cause"]."".$row["dialstatus"]."".$row["channel"]."".$caller_id."".$row["dial_time"]."".$row["answered_time"]."".$phone_number."".$row["sip_hangup_cause"]."".$row["sip_hangup_reason"]."
[<<< "._QXZ("PREV")." 1000 "._QXZ("records")."]"; + } else { + $carrier_rpt_hf.=sprintf("%-23s", " "); + $HTML.=" ["._QXZ("NEXT")." $max_limit "._QXZ("records")." >>>]"; + } else { + $carrier_rpt_hf.=sprintf("%23s", " "); + $HTML.=" 
"; + + } else { + $TEXT.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; + $HTML.="*** "._QXZ("NO RECORDS FOUND")." ***\n"; + } + $TEXT.="
\n"; + + if ($report_display_type=="HTML") { + $MAIN.=$HTML; + } else { + $MAIN.=$TEXT; + } + + $MAIN.="
\n"; + + +} + if ($file_download>0) { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_hangup_cause_report_$US$FILE_TIME.csv"; + $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); + $CSV_text=preg_replace('/\" +/', '"', $CSV_text); + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + + } else { + echo $HEADER; + require("admin_header.php"); + echo $MAIN; + } + +if ($db_source == 'S') + { + mysqli_close($link); + $use_slave_server=0; + $db_source = 'M'; + require("dbconnect_mysqli.php"); + } + +$endMS = microtime(); +$startMSary = explode(" ",$startMS); +$endMSary = explode(" ",$endMS); +$runS = ($endMSary[0] - $startMSary[0]); +$runM = ($endMSary[1] - $startMSary[1]); +$TOTALrun = ($runS + $runM); + +$END_TIME=date("U"); + +#print "Total run time: ".($END_TIME-$START_TIME); + +$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); + +exit; + +?> diff --git a/agc_2-X/trunk/www/vicidial/AST_inbound_forecasting.php b/agc_2-X/trunk/www/vicidial/AST_inbound_forecasting.php index f87a81f1..0d144d69 100644 --- a/agc_2-X/trunk/www/vicidial/AST_inbound_forecasting.php +++ b/agc_2-X/trunk/www/vicidial/AST_inbound_forecasting.php @@ -1,1344 +1,1344 @@ -, Joe Johnson LICENSE: AGPLv2 -# -# CHANGES -# -# 170428-1205 - First build -# 170504-2245 - Minor bug fixes -# 170829-0040 - Added screen color settings -# 171012-2015 - Fixed javascript/apache errors with graphs -# 180507-2315 - Added new help display -# 180712-1508 - Fix for rare allowed reports issue -# 191013-0856 - Fixes for PHP7 -# - -$startMS = microtime(); - -require("dbconnect_mysqli.php"); -require("functions.php"); - - function factorial($num) { - $num=floor($num); - if ($num>0) { - $result=1; - for ($x=1; $x<=$num; $x++) { - $result*=$x; - } - return $result; - } else { - return 1; - } - } - function erlsum($low, $limit, $erlangs) { - $result=0; - for ($n=$low; $n<=$limit; $n++) { - $result+=pow($erlangs, $n)/(factorial($n)); - } - return $result; - } - function adjustedGoS($erlangs, $GoS, $retry_rate, $lines) { - $E[0]=$erlangs; - $P[0]=$GoS; - - for ($q=0; $q<100; $q++) { - $E[($q+1)]=$erlangs+($retry_rate/100)*$E[$q]*$P[$q]; - $P[($q+1)]=MathZDC((pow($E[($q+1)], $lines)/(factorial($lines))), (erlsum(0, $lines, $E[($q+1)]))); - - } - return $P[100]; - } - -if (file_exists('options.php')) - { - require('options.php'); - } - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["group"])) {$group=$_GET["group"];} - elseif (isset($_POST["group"])) {$group=$_POST["group"];} -if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];} - elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];} -if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} - elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} - elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} -if (isset($_GET["drop_percent"])) {$drop_percent=$_GET["drop_percent"];} - elseif (isset($_POST["drop_percent"])) {$drop_percent=$_POST["drop_percent"];} -if (isset($_GET["shift"])) {$shift=$_GET["shift"];} - elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} -if (isset($_GET["erlang_type"])) {$erlang_type=$_GET["erlang_type"];} - elseif (isset($_POST["erlang_type"])) {$erlang_type=$_POST["erlang_type"];} -if (isset($_GET["actual_agents"])) {$actual_agents=$_GET["actual_agents"];} - elseif (isset($_POST["actual_agents"])) {$actual_agents=$_POST["actual_agents"];} -if (isset($_GET["hourly_pay"])) {$hourly_pay=$_GET["hourly_pay"];} - elseif (isset($_POST["hourly_pay"])) {$hourly_pay=$_POST["hourly_pay"];} -if (isset($_GET["revenue_per_sale"])) {$revenue_per_sale=$_GET["revenue_per_sale"];} - elseif (isset($_POST["revenue_per_sale"])) {$revenue_per_sale=$_POST["revenue_per_sale"];} -if (isset($_GET["sale_chance"])) {$sale_chance=$_GET["sale_chance"];} - elseif (isset($_POST["sale_chance"])) {$sale_chance=$_POST["sale_chance"];} -if (isset($_GET["retry_rate"])) {$retry_rate=$_GET["retry_rate"];} - elseif (isset($_POST["retry_rate"])) {$retry_rate=$_POST["retry_rate"];} -if (isset($_GET["target_pqueue"])) {$target_pqueue=$_GET["target_pqueue"];} - elseif (isset($_POST["target_pqueue"])) {$target_pqueue=$_POST["target_pqueue"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["submit"])) {$submit=$_GET["submit"];} - elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} -if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} - elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} - -if (strlen($shift)<2) {$shift='ALL';} - -$report_name = 'Inbound Forecasting Report'; -$db_source = 'M'; - -if ($ignore_afterhours=="checked") {$status_clause=" and status!='AFTHRS'";} - -$HTML_text=""; -$report_display_type="HTML"; - -# $actual_agents=preg_replace("/[^0-9.]/", "", $actual_agents); -# $actual_agents+=0; -# $hourly_pay=preg_replace("/[^0-9.]/", "", $hourly_pay); -# $hourly_pay+=0; -# $revenue_per_sale=preg_replace("/[^0-9.]/", "", $revenue_per_sale); -# $revenue_per_sale+=0; -# $sale_chance=preg_replace("/[^0-9.]/", "", $sale_chance); -# $sale_chance+=0; -# $retry_rate=preg_replace("/[^0-9.]/", "", $retry_rate); -# $retry_rate+=0; - -switch ($erlang_type) { - default: - case "B": - $erlB="checked"; - $erlC=""; - break; - case "C": - $erlB=""; - $erlC="checked"; - break; -} - -$JS_text="\n"; -$HEADER.=""; - -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -# $HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.="\n"; -$HEADER.=""._QXZ("$report_name")."\n"; - -$short_header=1; - -$MAIN.="
\n"; -$MAIN.=""._QXZ("$report_name")." $NWB#inbound_forecasting$NWE\n"; - -#$MAIN.="\n"; -$MAIN.="\n"; - -$MAIN.="\n"; - -$MAIN.="\n"; -# $MAIN.="\n"; -$MAIN.="
"._QXZ("Dates").":
"; -$MAIN.="\n"; - - -$MAIN.=""; - -$MAIN.="\n"; - -$MAIN.="
"._QXZ("to")."
"; - -$MAIN.="

"; -$MAIN.=""._QXZ("Target drop rate").":
% ("._QXZ("optional").")"; -# $MAIN.=""._QXZ("Target queue prob.").":% (C report)"; -$MAIN.="
"._QXZ("Campaigns").":
"; -$MAIN.="\n"; -$MAIN.="
"._QXZ("In-groups").":
\n"; -$MAIN.="
"._QXZ("Cost analysis stats (optional)").":
"; -# $MAIN.=_QXZ("Actual agents").":

"; -# $MAIN.=_QXZ("Hourly pay per agent").":
\$
"; -# $MAIN.=_QXZ("Revenue per sale").":
\$
"; -# $MAIN.=_QXZ("Chance of sale").":
%
"; -# $MAIN.=_QXZ("Retry rate").":
% (B "._QXZ("reports only").")"; -# $MAIN.="
"; -$MAIN.=""; -$MAIN.=""; - -# $MAIN.=""._QXZ("Erlang type").":
"; -# $MAIN.="B - "._QXZ("inbound/call loss stats")."
"; -# $MAIN.="C - "._QXZ("outbound/waiting time stats")."

"; - -# $MAIN.="  "; - - -if ($IDR_calltime_available==1) - { - $MAIN.="\n"; - } - -$MAIN.="


"._QXZ("Advanced Forecasting Report")."

"._QXZ("DOWNLOAD")." | "._QXZ("REPORTS")."
\n"; -# $MAIN.="
"; -$MAIN.="
";
-
-if ($groups_selected==0 && $campaigns_selected==0)
-	{
-	$MAIN.="\n\n";
-	$MAIN.=_QXZ("PLEASE SELECT AN IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT")."\n";
-	echo "$HEADER";
-	require("admin_header.php");
-	echo "$MAIN";
-	}
-else
-	{
-	$campaign_group_stmt="select closer_campaigns from vicidial_campaigns where campaign_id in ($campaign_SQL)";
-	if ($DB) {echo "|$campaign_group_stmt|\n";}
-	$campaign_group_rslt=mysql_to_mysqli($campaign_group_stmt, $link);
-	$campaign_group_SQL="";
-	while ($cg_row=mysqli_fetch_row($campaign_group_rslt)) {
-		if (strlen(trim($cg_row[0]))>0) {
-			$cg_row[0]=preg_replace("/^\s+|\s\-/", "", $cg_row[0]);
-			$campaign_group_SQL.="'".preg_replace("/\s/", "','", $cg_row[0])."',";
-		}		
-	}
-	$campaign_group_SQL=$group_SQL.",".$campaign_group_SQL;
-	$campaign_group_SQL=preg_replace("/^,|,$/", "", $campaign_group_SQL);
-
-	$campaign_string=preg_replace("/^\||\|$/", "", $campaign_string);
-	$group_string=preg_replace("/^\||\|$/", "", $group_string);
-	$ASCII_text =" Date range :  $query_date to $end_date\n";
-	$ASCII_text.=" Campaigns  :  ".preg_replace("/\|/", ", ", $campaign_string)."\n";
-	$ASCII_text.=" In-groups  :  ".preg_replace("/\|/", ", ", $group_string)."\n\n";
-# 	$ASCII_text.=" Report type:  $erlang_type\n\n";
-
-	$HTML_text.=" Date range :  $query_date to $end_date\n";
-	$HTML_text.=" Campaigns  :  ".preg_replace("/\|/", ", ", $campaign_string)."\n";
-	$HTML_text.=" In-groups  :  ".preg_replace("/\|/", ", ", $group_string)."";
-# 	$HTML_text.=" Report type:  $erlang_type\n\n";
-	
-	$sale_stmt="select distinct status from vicidial_campaign_statuses where campaign_id in ($campaign_SQL) and sale='Y' UNION select status from vicidial_statuses where sale='Y'";
-	if ($DB) {echo "|$sale_stmt|\n";}
-	$sale_rslt=mysql_to_mysqli($sale_stmt, $link);
-	$sales_array=array();
-	while ($sale_row=mysqli_fetch_row($sale_rslt)) {
-		array_push($sales_array, "$sale_row[0]");
-	}
-
-	if ($erlang_type=="B") {
-		$hour_stmt="select closecallid, substr(call_date, 1, 13) as start_hour, length_in_sec, substr(call_date+INTERVAL length_in_sec second, 1, 13) as end_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'))-UNIX_TIMESTAMP(call_date), length_in_sec) as length_up_to_next_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(call_date+INTERVAL length_in_sec second)-UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00')), 0) as length_running_into_next_hour, status, uniqueid from vicidial_closer_log where length_in_sec is not null and campaign_id in ($campaign_group_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59' and status!='AFTHRS'"; # *
-
-		$avg_stmt="select avg(length_in_sec) as avg_length from vicidial_closer_log where length_in_sec is not null and campaign_id in ($campaign_group_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # **
-
-		$wrapup_stmt="select uniqueid from vicidial_closer_log where length_in_sec is not null and user!='VDCL' and campaign_id in ($campaign_group_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # ***
-	} else {
-		$hour_stmt="select uniqueid, substr(call_date, 1, 13) as start_hour, length_in_sec, substr(call_date+INTERVAL length_in_sec second, 1, 13) as end_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'))-UNIX_TIMESTAMP(call_date), length_in_sec) as length_up_to_next_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(call_date+INTERVAL length_in_sec second)-UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00')), 0) as length_running_into_next_hour, status, uniqueid from vicidial_log where length_in_sec is not null and campaign_id in ($campaign_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59' and status!='AFTHRS'"; # *
-
-		$avg_stmt="select avg(length_in_sec) as avg_length from vicidial_log where length_in_sec is not null and campaign_id in ($campaign_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # **
-
-		$wrapup_stmt="select uniqueid from vicidial_log where length_in_sec is not null and user!='VDCL' and campaign_id in ($campaign_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # ***
-	}
-	if ($DB) {echo "|$hour_stmt|\n";}
-	if ($DB) {echo "|$avg_stmt|\n";}
-	if ($DB) {echo "|$wrapup_stmt|\n";}
-
-	# $ASCII_text.=$hour_stmt."
\n"; - $hour_rslt=mysql_to_mysqli($hour_stmt, $link); # * - $erlang_calls=mysqli_num_rows($hour_rslt); - - # PROVIDE ACTUAL STATS - $avg_rslt=mysql_to_mysqli($avg_stmt, $link); # ** - $avg_row=mysqli_fetch_array($avg_rslt); - $average_call_length=$avg_row["avg_length"]; - - $wrapup_rslt=mysql_to_mysqli($wrapup_stmt, $link); # *** - $wrapup_calls=mysqli_num_rows($wrapup_rslt); - $uid_ct=0; - $uid_clause=""; - $dispo_secs=0; - $talk_secs=0; - while ($wrapup_row=mysqli_fetch_row($wrapup_rslt)) { - $uid_ct++; - $uid_clause.="'$wrapup_row[0]',"; - if ($uid_ct%100==0) { - $uid_clause=preg_replace('/,$/', '', $uid_clause); - $uid_stmt="select dispo_sec, talk_sec from vicidial_agent_log where uniqueid in ($uid_clause)"; - $uid_rslt=mysql_to_mysqli($uid_stmt, $link); - while ($uid_row=mysqli_fetch_row($uid_rslt)) { - $dispo_secs+=$uid_row[0]; - $talk_secs+=$uid_row[1]; - } - $uid_clause=""; - } - } - if (strlen($uid_clause)>0) { - $uid_clause=preg_replace('/,$/', '', $uid_clause); - $uid_stmt="select dispo_sec, talk_sec from vicidial_agent_log where uniqueid in ($uid_clause)"; - $uid_rslt=mysql_to_mysqli($uid_stmt, $link); - while ($uid_row=mysqli_fetch_row($uid_rslt)) { - $dispo_secs+=$uid_row[0]; - $talk_secs+=$uid_row[1]; - } - $uid_clause=""; - } - $avg_dispo_sec=MathZDC($dispo_secs, $wrapup_calls); - $avg_talk_sec=MathZDC($talk_secs, $wrapup_calls); - ##### - - - $wrapup_stmt="select average(dispo_sec) from vicidial_agent_log"; - - $erlang_array=array(); - $drops_blocks=0; - $sales=0; - while ($hour_row=mysqli_fetch_array($hour_rslt)) { - $erlang_array["$hour_row[start_hour]"][0]+=$hour_row["length_up_to_next_hour"]; - $erlang_array["$hour_row[start_hour]"][2]++; - - if ($hour_row["length_running_into_next_hour"]>0) { - $erlang_array["$hour_row[end_hour]"][0]+=$hour_row["length_running_into_next_hour"]; - $erlang_array["$hour_row[end_hour]"][2]++; - if ($hour_row["status"]=="DROP") { - $erlang_array["$hour_row[end_hour]"][3]++; - } - } - - if ($hour_row["status"]=="DROP") { - $erlang_array["$hour_row[start_hour]"][1]+=$hour_row["length_up_to_next_hour"]; - $erlang_array["$hour_row[end_hour]"][1]+=$hour_row["length_running_into_next_hour"]; - $erlang_array["$hour_row[start_hour]"][3]++; - $drops_blocks++; - } - - if (in_array("$hour_row[status]", $sales_array)) { - $erlang_array["$hour_row[start_hour]"][4]++; - $sales++; - } - } - $hours_active=count($erlang_array); # Used for giving total erlangs for day, need to divide by number of hours reported, not one hour - $total_erlangs=MathZDC(($erlang_calls*$average_call_length),(3600*$hours_active)); - $total_blocking=MathZDC($drops_blocks, $erlang_calls); - $sale_percent=MathZDC($sales, $erlang_calls); - - $rpt_header ="+-----------------+-------+-------+------------+----------+-------------+----------+---------+"; - if ($erlang_type=="B") {$rpt_header.="---------+";} - if ($erlang_type=="C") {$rpt_header.="------------+------------+";} - $rpt_header.="------------+------------+------------+----------+-----------+------------+------------+------------+\n"; - - $ASCII_text.=$rpt_header; - # $ASCII_text.=$hour_stmt."
\n"; - - # Damn fixed-space formatting, hate ASCII. HATE. - if ($erlang_type=="B") { - if ($actual_agents>0) { - $ASCII_text.="| ".sprintf("%70s", _QXZ("Actual agents: ")).sprintf("%-131s", "$actual_agents")." |\n"; - } - $ASCII_text.="| ".sprintf("%70s", _QXZ("Total calls: ")).sprintf("%-131s", "$erlang_calls")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Total drops: ")).sprintf("%-131s", "$drops_blocks")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired drop rate: ")).sprintf("%-5.2f", "$drop_percent").sprintf("%-126s", " %")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Total blocking/drop rate: ")).sprintf("%-5.2f", (100*$total_blocking)).sprintf("%-126s", " %")." |\n"; # sprintf("%-131.4f", "$total_blocking") - # $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired sale rate: ")).sprintf("%-5.2f", "$sale_chance").sprintf("%-126s", " %")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Sale rate: ")).sprintf("%-5.2f", (100*$sale_percent)).sprintf("%-126s", " %")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Average call duration: ")).sprintf("%-131.2f", "$average_call_length")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Erlangs: ")).sprintf("%-131.4f", $total_erlangs)." |\n"; - } - if ($erlang_type=="C") { - if ($actual_agents>0) { - $ASCII_text.="| ".sprintf("%70s", _QXZ("Actual agents: ")).sprintf("%-147s", "$actual_agents")." |\n"; - } - $ASCII_text.="| ".sprintf("%70s", _QXZ("Total calls: ")).sprintf("%-147s", "$erlang_calls")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Total drops: ")).sprintf("%-147s", "$drops_blocks")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired drop rate: ")).sprintf("%-5.2f", "$drop_percent").sprintf("%-142s", " %")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Total blocking/drop rate: ")).sprintf("%-5.2f", (100*$total_blocking)).sprintf("%-142s", " %")." |\n"; # sprintf("%-147.4f", "$total_blocking") - # $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired sale rate: ")).sprintf("%-5.2f", "$sale_chance").sprintf("%-142s", " %")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Sale rate: ")).sprintf("%-5.2f", (100*$sale_percent)).sprintf("%-142s", " %")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Average call duration: ")).sprintf("%-147.2f", "$average_call_length")." |\n"; - $ASCII_text.="| ".sprintf("%70s", _QXZ("Erlangs: ")).sprintf("%-147.4f", $total_erlangs)." |\n"; - } - - $HTML_text.=""; - $HTML_text.=""; # B -# $HTML_text.=""; # B - } - if ($erlang_type=="C") { - $HTML_text.=""; # C - $HTML_text.=""; # C - } -# $HTML_text.=""; - ############# - - ##### RECOMMENDED AGENTS - $lines=1; - if ($erlang_type=="B") { - $GoS=MathZDC((pow($total_erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $total_erlangs))); - if ($GoS>$drop_rate) { - $ASCII_text.=""; - } - } - if ($erlang_type=="C") { - $Pqueue=(pow($total_erlangs, $lines)/(factorial($lines)))/((pow($total_erlangs, $lines)/(factorial($lines)))+((1-MathZDC($total_erlangs, $lines))*erlsum(0, ($lines-1), $total_erlangs))); - if ($Pqueue>$pqueue_target) { - $ASCII_text.=""; - } - } - - if ($erlang_type=="B") { - $ASCII_text.="| ".sprintf("%70s", _QXZ("Recommended agent count: ")).sprintf("%-131s", $lines)." |\n"; - } else { - $ASCII_text.="| ".sprintf("%70s", _QXZ("Recommended agent count: ")).sprintf("%-147s", $lines)." |\n"; - } - $CSV_text.="\"Recommended agent count:\",\"$lines\"\n"; - $CSV_text.="\n"; - ############# - - $ASCII_text.=$rpt_header; - $ASCII_text.= "| "._QXZ("CALLING HOUR", 15)." | "._QXZ("CALLS", 5)." | "._QXZ("SALES", 5)." | "._QXZ("TOTAL TIME", 10)." | "._QXZ("AVG TIME", 8)." | "._QXZ("DROPPED HRS", 11)." | "._QXZ("BLOCKING", 8)." | "._QXZ("ERLANGS", 7); - if ($erlang_type=="B") {$ASCII_text.=" | "._QXZ("GOS", 7);} # B - if ($erlang_type=="C") {$ASCII_text.=" | "._QXZ("QUEUE PROB", 10)." | "._QXZ("AVG ANSWER", 10);} # C - $ASCII_text.=" | "._QXZ("REC AGENTS", 10)." | "._QXZ("EST AGENTS", 10)." | "._QXZ("CALLS/AGNT", 10)." |\n"; # ." | "._QXZ("REV/CALL", 8)." | "._QXZ("REV/AGENT", 9)." | "._QXZ("TOTAL REV", 10)." | "._QXZ("TOTAL COST", 10)." | "._QXZ("MARGIN", 10) - $ASCII_text.=$rpt_header; - $CSV_text.="\""._QXZ("CALLING HOUR")."\",\""._QXZ("CALLS")."\",\""._QXZ("SALES")."\",\""._QXZ("TOTAL TIME")."\",\""._QXZ("AVG TIME")."\",\""._QXZ("DROPPED HRS")."\",\""._QXZ("BLOCKING")."\",\""._QXZ("ERLANGS")."\","; - if ($erlang_type=="B") {$CSV_text.="\""._QXZ("GRADE OF SERVICE")."\",";} # B - if ($erlang_type=="C") {$CSV_text.="\""._QXZ("QUEUE PROBABILITY")."\",\""._QXZ("AVERAGE ANSWER SPEED")."\",";} # C - $CSV_text.="\""._QXZ("REC AGENTS")."\",\""._QXZ("EST AGENTS")."\",\""._QXZ("CALLS/AGNT")."\"\n"; # ,\""._QXZ("REV/CALL")."\",\""._QXZ("REV/AGENT")."\",\""._QXZ("TOTAL REV")."\",\""._QXZ("TOTAL COST")."\",\""._QXZ("MARGIN")."\" - ksort($erlang_array); - - $HTML_text2=""; - $HTML_text2.="
"; - - $CSV_text=""; - if ($actual_agents>0) { - $CSV_text.="\"Actual agents:\",\"$actual_agents\"\n"; - } - $CSV_text.="\"Total calls:\",\"$erlang_calls\"\n"; - $CSV_text.="\"Total drops:\",\"$drops_blocks\"\n"; - $CSV_text.="\"Desired drop rate:\",\"".sprintf("%5.2f", "$drop_percent")." %\"\n"; - $CSV_text.="\"Total blocking/drop rate:\",\"".sprintf("%-5.2f", (100*$total_blocking))."\"\n"; - # $CSV_text.="\"Desired sale rate:\",\"".sprintf("%5.2f", "$sale_chance")." %\"\n"; - $CSV_text.="\"Sale rate:\",\"".sprintf("%-5.2f", (100*$sale_percent))."\"\n"; - $CSV_text.="\"Average call duration:\",\"".sprintf("%.2f", "$average_call_length")." seconds\"\n"; - $CSV_text.="\"Erlangs:\",\"".sprintf("%.4f", "$total_erlangs")."\"\n"; - - - # ESTIMATED AGENTS - $lines=1; - if ($total_blocking>0) { - $GoS=MathZDC((pow($total_erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $total_erlangs))); - if ($GoS>$total_blocking) { - $ASCII_text.=""; - } - $Pqueue=(pow($total_erlangs, $lines)/(factorial($lines)))/((pow($total_erlangs, $lines)/(factorial($lines)))+((1-MathZDC($total_erlangs, $lines))*erlsum(0, ($lines-1), $total_erlangs))); - $ASA=MathZDC(($Pqueue*$average_call_length), ($lines-$total_erlangs)); - } else { - $lines="N/A"; - $Pqueue=0; - $ASA=0; - } - if ($Pqueue>1) {$Pqueue=1;} - $est_GoS=$GoS; # Need this here since we moved the output line further down & need to save it. - $est_lines=$lines; # Need this here since we moved the output line further down & need to save it. - - if ($erlang_type=="B") { -# $ASCII_text.="| ".sprintf("%70s", _QXZ("Retry rate: ")).sprintf("%-131s", "$retry_rate %")." |\n"; # B - $ASCII_text.="| ".sprintf("%70s", _QXZ("Grade of service: ")).sprintf("%-131s", sprintf("%0.2f", (100*$GoS)." %"))." |\n"; # B - $ASCII_text.="| ".sprintf("%70s", _QXZ("Estimated agents fielding calls: ")).sprintf("%-131s", $lines)." |\n"; - } - if ($erlang_type=="C") { - $ASCII_text.="| ".sprintf("%70s", _QXZ("Estimated queue probability: ")).sprintf("%-5.2f", (100*$Pqueue)).sprintf("%-142s", " %")." |\n"; # C - $ASCII_text.="| ".sprintf("%70s", _QXZ("Average speed of answering: ")).sprintf("%-147s", sec_convert($ASA,'H'))." |\n"; # C - $ASCII_text.="| ".sprintf("%70s", _QXZ("Estimated agents fielding calls: ")).sprintf("%-147s", $lines)." |\n"; - } - - if ($erlang_type=="B") { -# $CSV_text.="\""._QXZ("Retry rate: ")."\",\"$retry_rate %\"\n"; # B - $CSV_text.="\""._QXZ("Grade of service: ")."\",\"".sprintf("%0.2f", (100*$GoS))." %\"\n"; # B - } - if ($erlang_type=="C") { - $CSV_text.="\""._QXZ("Estimated queue probability: ")."\",\"".sprintf("%.2f", (100*$Pqueue))."%\"\n"; # C - $CSV_text.="\""._QXZ("Average speed of answering: ")."\",\"".sec_convert($ASA,'H')."\"\n"; # C - } - $CSV_text.="\""._QXZ("Estimated agents fielding calls: ")."\",\"$lines\"\n"; - - if ($erlang_type=="B") { -## $HTML_text.="
"._QXZ("Retry rate: ")."$retry_rate %
"._QXZ("Grade of service: ")."".sprintf("%0.2f", (100*$GoS))."%
"._QXZ("Estimated queue probability: ")."".sprintf("%.2f", (100*$Pqueue))."%
"._QXZ("Average speed of answering: ")."".sec_convert($ASA,'H')."
"._QXZ("Estimated agents fielding calls: ")."".$lines."
"; - $HTML_text2.="
"; - $HTML_text2.=""; - if ($actual_agents>0) { - $HTML_text2.=""; - } - $HTML_text2.=""; - $HTML_text2.=""; - $HTML_text2.=""; - $HTML_text2.=""; - # $HTML_text2.=""; - $HTML_text2.=""; - $HTML_text2.=""; - $HTML_text2.=""; - $HTML_text2.=""; # B - $HTML_text2.=""; - $HTML_text2.=""; - $HTML_text2.="
"._QXZ("INBOUND SUMMARY")."
"._QXZ("Actual agents: ")."".$actual_agents."
"._QXZ("Total calls: ")."".$erlang_calls."
"._QXZ("Total drops: ")."".$drops_blocks."
"._QXZ("Desired drop rate: ")."".sprintf("%5.2f", "$drop_percent")." %
"._QXZ("Total blocking/drop rate: ")."".sprintf("%-5.2f", (100*$total_blocking))." %
"._QXZ("Desired sale rate: ")."".sprintf("%5.2f", "$sale_chance")." %
"._QXZ("Sale rate: ")."".sprintf("%-5.2f", (100*$sale_percent))." %
"._QXZ("Average call duration: ")."".sprintf("%18.2f", "$average_call_length")."
"._QXZ("Erlangs: ")."".sprintf("%18.4f", $total_erlangs)."
"._QXZ("Grade of service: ")."".sprintf("%0.2f", (100*$est_GoS))."%
"._QXZ("Estimated agents fielding calls: ")."".$est_lines."
"._QXZ("Recommended agent count: ")."".$lines."
"; - $HTML_text2.="
"; # For closing the table above that encompasses first report table and chart - - $HTML_text2.=""; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - - if ($erlang_type=="B") { - $HTML_text2.="\n"; # B - } - if ($erlang_type=="C") { - $HTML_text2.="\n"; # C - $HTML_text2.="\n"; # C - } - - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - # $HTML_text2.="\n"; - # $HTML_text2.="\n"; - # $HTML_text2.="\n"; - # $HTML_text2.="\n"; - # $HTML_text2.="\n"; - $HTML_text2.="\n"; - - - $bht=0; - $graph_stats=array(); - $q=0; -# while(list($key, $val)=each($erlang_array)) { - foreach($erlang_array as $key => $val) { - if ($val[0]>$bht) {$bht=$val[0];} - if ($q%2==0) {$tdclass="records_list_x";} else {$tdclass="records_list_y";} - $average_time=round(MathZDC($val[0], $val[2])); - $blocking=MathZDC($val[3], $val[2]); - $erlangs=$val[2]*MathZDC($average_time, 3600); # Row is call per hour, therefore call length average must be in hours. - $sales=$val[4]+0; - - $ASCII_text.="| "; #.substr($key, 0, -2)." - ".substr($key, 5, 2)." ".substr($key, 8, 2)." ".substr($key, 0, 4); - $ASCII_text.=date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4))); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%5s", $val[2]); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%5s", $sales); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%10s", sec_convert($val[0],'H')); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%8s", sec_convert($average_time,'H')); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%11s", sec_convert($val[1],'H')); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%8s", sprintf("%01.4f", $blocking)); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%7s", sprintf("%01.4f", $erlangs)); - $ASCII_text.=" | "; - - $CSV_text.="\"".date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4)))."\",\"".$val[2]."\",\"".$sales."\",\"".sec_convert($val[0],'H')."\",\"".sec_convert($average_time,'H')."\",\"".sec_convert($val[1],'H')."\",\"".sprintf("%01.4f", $blocking)."\",\"".sprintf("%01.4f", $erlangs)."\","; - - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - $HTML_text2.="\n"; - - $graph_key=date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4))); - $graph_stats["$graph_key"][0]=$val[2]; - $graph_stats["$graph_key"][1]=$val[0]; - $graph_stats["$graph_key"][2]=$average_time; - $graph_stats["$graph_key"][3]=$val[1]; - $graph_stats["$graph_key"][4]=sprintf("%01.4f", $blocking); - $graph_stats["$graph_key"][5]=sprintf("%01.4f", $erlangs); - - ##### RECOMMENDED AGENTS - $lines=1; - if ($erlang_type=="B") { - $GoS=MathZDC((pow($erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $erlangs))); - if ($GoS>$drop_rate) { - $ASCII_text.=""; - } - } - if ($erlang_type=="C") { - $Pqueue=(pow($erlangs, $lines)/(factorial($lines)))/((pow($erlangs, $lines)/(factorial($lines)))+((1-MathZDC($erlangs, $lines))*erlsum(0, ($lines-1), $erlangs))); - if ($Pqueue>$pqueue_target) { - $ASCII_text.=""; - } - } - $recommended_agents=$lines; - - ##### ESTIMATED AGENTS - $lines=1; - if ($blocking>0) { - $GoS=MathZDC((pow($erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $erlangs))); - if ($GoS>$blocking) { - $ASCII_text.=""; - } - - $Pqueue=(pow($erlangs, $lines)/(factorial($lines)))/((pow($erlangs, $lines)/(factorial($lines)))+((1-MathZDC($erlangs, $lines))*erlsum(0, ($lines-1), $erlangs))); - $ASA=MathZDC(($Pqueue*$average_time), ($lines-$erlangs)); - } else { - $lines="$recommended_agents"; - $Pqueue=0; - $ASA=0; - } - if ($actual_agents>0) { - $lines=$actual_agents; - $Pqueue=0; - $ASA=0; - } - if ($Pqueue>1) {$Pqueue=1;} - - if ($erlang_type=="B") { - $ASCII_text.=sprintf("%7s", sprintf("%0.2f", (100*$GoS))."%"); - $ASCII_text.=" | "; - } - if ($erlang_type=="C") { - $ASCII_text.=sprintf("%10s", sprintf("%.4f", (100*$Pqueue))."%"); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%10s", sec_convert($ASA,'H')); - $ASCII_text.=" | "; - } - $ASCII_text.=sprintf("%10s", $recommended_agents); - $ASCII_text.=" | "; - if ($erlang_type=="B") { - $CSV_text.="\"".sprintf("%0.2f", (100*$GoS))."%\","; # B - } - if ($erlang_type=="C") { - $CSV_text.="\"".sprintf("%.6f", (100*$Pqueue))."%\","; # C - $CSV_text.="\"".sec_convert($ASA,'H')."\","; # C - } - $CSV_text.="\"$recommended_agents\","; - $graph_stats["$graph_key"][7]=$recommended_agents; - if ($erlang_type=="B") { - $HTML_text2.="\n"; # B - } - if ($erlang_type=="C") { - $HTML_text2.="\n"; # C - $HTML_text2.="\n"; # C - } - $HTML_text2.="\n"; - - $ASCII_text.=sprintf("%10s", $lines); - $ASCII_text.=" | "; - $ASCII_text.=sprintf("%-10.2f", MathZDC($val[2], $lines)); -# $ASCII_text.=" | "; -# $ASCII_text.=sprintf("%-8s", "\$".number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",",")); -# $ASCII_text.=" | "; -# $ASCII_text.=sprintf("%-9s", "\$".number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",",")); -# $ASCII_text.=" | "; -# $ASCII_text.=sprintf("%-10s", "\$".number_format(($revenue_per_sale*$sales),2,".",",")); -# $ASCII_text.=" | "; -# $ASCII_text.=sprintf("%-10s", "\$".number_format(($lines*$hourly_pay),2,".",",")); -# $ASCII_text.=" | "; -# $ASCII_text.=sprintf("%-10s", "\$".number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",",")); - $ASCII_text.=" |\n"; - - $graph_stats["$graph_key"][8]=$drop_rate; - - - $CSV_text.="\"$lines\","; - $CSV_text.="\"".sprintf("%.2f", MathZDC($val[2], $lines))."\","; -# $CSV_text.="\"$".number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",",")."\","; -# $CSV_text.="\"$".number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",",")."\","; -# $CSV_text.="\"$".number_format(($revenue_per_sale*$sales),2,".",",")."\","; -# $CSV_text.="\"$".number_format(($lines*$hourly_pay),2,".",",")."\","; -# $CSV_text.="\"$".number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",",")."\"\n"; - - $graph_stats["$graph_key"][6]=$lines; - $graph_stats["$graph_key"][8]=$drop_rate; - $graph_stats["$graph_key"][9]=$sales; - $graph_stats["$graph_key"][10]=number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",""); # Revenue per call - $graph_stats["$graph_key"][11]=number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",""); # Revenue per agent - $graph_stats["$graph_key"][12]=number_format(($revenue_per_sale*$sales),2,".",""); # Total revenue - $graph_stats["$graph_key"][13]=number_format(($lines*$hourly_pay),2,".",""); # Cost - $graph_stats["$graph_key"][14]=number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",","); - $graph_stats["$graph_key"][15]=$GoS; - $graph_stats["$graph_key"][16]=$Pqueue; # Cost - $graph_stats["$graph_key"][17]=$ASA; # Cost - - $HTML_text2.="\n"; - $HTML_text2.="\n"; -# $HTML_text2.="\n"; -# $HTML_text2.="\n"; -# $HTML_text2.="\n"; -# $HTML_text2.="\n"; -# $HTML_text2.="\n"; - $HTML_text2.="\n"; - $q++; - } - $ASCII_text.=$rpt_header; - $ASCII_text.=" BHT: ".sec_convert($bht,'H')." ($bht seconds)\n"; - - $HTML_text2.="
"._QXZ("CALLING HOUR").""._QXZ("CALLS").""._QXZ("SALES").""._QXZ("TOTAL TIME").""._QXZ("AVG TIME").""._QXZ("DROPPED HRS").""._QXZ("BLOCKING").""._QXZ("ERLANGS").""._QXZ("GRADE OF SERVICE").""._QXZ("QUEUE PROB").""._QXZ("AVG ANSWER").""._QXZ("REC AGENTS").""._QXZ("EST AGENTS").""._QXZ("CALLS PER AGENT").""._QXZ("REVENUE PER CALL").""._QXZ("REVENUE PER AGENT").""._QXZ("TOTAL REVENUE").""._QXZ("TOTAL COST").""._QXZ("MARGIN")."
".date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4)))."".$val[2]."".$sales."".sec_convert($val[0],'H')."".sec_convert($average_time,'H')."".sec_convert($val[1],'H')."".sprintf("%01.4f", $blocking)."".sprintf("%01.4f", $erlangs)."".sprintf("%0.2f", (100*$GoS))."%".sprintf("%.4f", (100*$Pqueue))."%".sec_convert($ASA,'H')." $recommended_agents$lines".sprintf("%.2f", ($val[2]/$lines))."\$".number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",",")."\$".number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",",")."\$".number_format(($revenue_per_sale*$sales),2,".",",")."\$".number_format(($lines*$hourly_pay),2,".",",")."\$".number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",",")."
"; - - # USE THIS FOR COMBINED graphs, use pipe-delimited array elements, dataset_name|index|link_name|graph_override - # You have to hard code the graph name in where it is overridden and mind the data indices. No other way to do it. - $multigraph_text=""; - $graph_id++; - $graph_array=array("ERL_AGENTSdata|7,6|AGENTS|integer|Rec. Agents,Est. Agents", "ERL_BLOCKdata|4,8|BLOCKING/DROPS|percent|Blocking,Desired drop rate", "ERL_CALLSdata|0,9|CALLS|integer|Calls,Sales", "ERL_TIMEdata|2,3,1|TIMES|time|Average time,Dropped time,Total time", "ERL_ERLANGSdata|5|ERLANGS|integer|Erlangs"); # , "ERL_REVENUEdata|10,11|REVENUE|dollar|Revenue per call,Revenue per agent", "ERL_REVENUEdata|12,13|MARGINS|dollar|Total revenue,Total cost" - if ($erlang_type=="B") { - array_push($graph_array, "ERL_GOSdata|15|GoS|integer|Grade of Service"); - } - if ($erlang_type=="C") { - array_push($graph_array, "ERL_PQUEUEdata|16|QUEUE|percent|Call queue probability"); - } - - - $default_graph="line"; # Graph that is initally displayed when page loads - include("graph_color_schemas.inc"); - - - # CUSTOMIZING COLORS FOR LINE GRAPHS - $graph_colors=array("216,0,0", "0,0,216", "0,216,0", "216,216,0", "216,0,216", "0,216,216"); - - - $graph_totals_array=array(); - $graph_totals_rawdata=array(); - for ($q=0; $q $val) { - $labels.="\"".preg_replace('/ +/', ' ', $key)."\","; - } - reset($graph_stats); - $labels=preg_replace('/,$/', '', $labels)."],\n"; - - for ($d=0; $d $val) { - $val[$dataset_index]=preg_replace("/N\/A/", "0", $val[$dataset_index]); - $data.="\"".$val[$dataset_index]."\","; - $current_graph_total+=intval($val[$dataset_index]); - $bgcolor=$backgroundColor[($d%count($backgroundColor))]; - $hbgcolor=$hoverBackgroundColor[($d%count($hoverBackgroundColor))]; - $hbcolor=$hoverBorderColor[($d%count($hoverBorderColor))]; - } - reset($graph_stats); - $data=preg_replace('/,$/', '', $data)."],\n"; - $datasets.=$data; - $datasets.=$graphConstantsA.$graphConstantsB.$graphConstantsC; # SEE TOP OF SCRIPT - $datasets.="\t\t\t},\n"; - $graph_totals_rawdata[$d]=$current_graph_total; - } - $datasets=preg_replace('/,\n$/', "\n", $datasets); - - switch($dataset_type) { - case "time": - $chart_options="options: {tooltips: {callbacks: {label: function(tooltipItem, data) {var value = Math.round(data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]); return data.datasets[tooltipItem.datasetIndex].label+\": \"+value.toHHMMSS();}}}, legend: { display: true }},"; - break; - case "percent": - $chart_options="options: {tooltips: {callbacks: {label: function(tooltipItem, data) {var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; return data.datasets[tooltipItem.datasetIndex].label+\": \"+ (value*100) + '%';}}}, legend: { display: true }},"; - break; - case "dollar": - $chart_options="options: {tooltips: {callbacks: {label: function(tooltipItem, data) {var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; return data.datasets[tooltipItem.datasetIndex].label+\": \$\"+ value;}}}, legend: { display: true }},"; - break; - default: - $chart_options="options: { legend: { display: true}},"; - break; - } - - $datasets.="\t\t]\n"; - $datasets.="\t}\n"; - - $JS_text.=$labels.$datasets; - $JS_text.="var main_ctx = document.getElementById(\"CanvasID".$graph_id."_".$q."\");\n"; - $JS_text.="var GraphID".$graph_id."_".$q." = new Chart(main_ctx, {type: '$default_graph', $chart_options data: $dataset_name});\n"; - } - - - $graph_count=count($graph_array); - $graph_title=_QXZ("FORECASTING REPORT"); - $hide_graph_choice="yes"; - $override_width=900; $override_height=500; - include("graphcanvas.inc"); - $HEADER.=$HTML_graph_head; - $GRAPH.=$graphCanvas; - - - if ($report_display_type=="HTML") - { - $JS_onload.="}\n"; - $JS_text.=$JS_onload; - $JS_text.="\n"; - require("chart_button.php"); - - $MAIN.=$HTML_text.$GRAPH.$HTML_text2.$JS_text; - } - else - { - $MAIN.=$ASCII_text; - } - - - $MAIN.=""; - -if ($file_download>0) - { - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "AST_Erlang_report_$US$FILE_TIME.csv"; - $CSV_text=preg_replace('/\n +,/', ',', $CSV_text); - $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); - $CSV_text=preg_replace('/\" +/', '"', $CSV_text); - - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - // It will be called LIST_101_20090209-121212.txt - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - } -else - { - header("Content-type: text/html; charset=utf-8"); - - echo "$HEADER"; - require("admin_header.php"); - echo "$MAIN"; - flush(); - } -# echo $ASCII_text; - } +, Joe Johnson LICENSE: AGPLv2 +# +# CHANGES +# +# 170428-1205 - First build +# 170504-2245 - Minor bug fixes +# 170829-0040 - Added screen color settings +# 171012-2015 - Fixed javascript/apache errors with graphs +# 180507-2315 - Added new help display +# 180712-1508 - Fix for rare allowed reports issue +# 191013-0856 - Fixes for PHP7 +# + +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + + function factorial($num) { + $num=floor($num); + if ($num>0) { + $result=1; + for ($x=1; $x<=$num; $x++) { + $result*=$x; + } + return $result; + } else { + return 1; + } + } + function erlsum($low, $limit, $erlangs) { + $result=0; + for ($n=$low; $n<=$limit; $n++) { + $result+=pow($erlangs, $n)/(factorial($n)); + } + return $result; + } + function adjustedGoS($erlangs, $GoS, $retry_rate, $lines) { + $E[0]=$erlangs; + $P[0]=$GoS; + + for ($q=0; $q<100; $q++) { + $E[($q+1)]=$erlangs+($retry_rate/100)*$E[$q]*$P[$q]; + $P[($q+1)]=MathZDC((pow($E[($q+1)], $lines)/(factorial($lines))), (erlsum(0, $lines, $E[($q+1)]))); + + } + return $P[100]; + } + +if (file_exists('options.php')) + { + require('options.php'); + } + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];} + elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];} +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} + elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} +if (isset($_GET["drop_percent"])) {$drop_percent=$_GET["drop_percent"];} + elseif (isset($_POST["drop_percent"])) {$drop_percent=$_POST["drop_percent"];} +if (isset($_GET["shift"])) {$shift=$_GET["shift"];} + elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} +if (isset($_GET["erlang_type"])) {$erlang_type=$_GET["erlang_type"];} + elseif (isset($_POST["erlang_type"])) {$erlang_type=$_POST["erlang_type"];} +if (isset($_GET["actual_agents"])) {$actual_agents=$_GET["actual_agents"];} + elseif (isset($_POST["actual_agents"])) {$actual_agents=$_POST["actual_agents"];} +if (isset($_GET["hourly_pay"])) {$hourly_pay=$_GET["hourly_pay"];} + elseif (isset($_POST["hourly_pay"])) {$hourly_pay=$_POST["hourly_pay"];} +if (isset($_GET["revenue_per_sale"])) {$revenue_per_sale=$_GET["revenue_per_sale"];} + elseif (isset($_POST["revenue_per_sale"])) {$revenue_per_sale=$_POST["revenue_per_sale"];} +if (isset($_GET["sale_chance"])) {$sale_chance=$_GET["sale_chance"];} + elseif (isset($_POST["sale_chance"])) {$sale_chance=$_POST["sale_chance"];} +if (isset($_GET["retry_rate"])) {$retry_rate=$_GET["retry_rate"];} + elseif (isset($_POST["retry_rate"])) {$retry_rate=$_POST["retry_rate"];} +if (isset($_GET["target_pqueue"])) {$target_pqueue=$_GET["target_pqueue"];} + elseif (isset($_POST["target_pqueue"])) {$target_pqueue=$_POST["target_pqueue"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} + elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} + +if (strlen($shift)<2) {$shift='ALL';} + +$report_name = 'Inbound Forecasting Report'; +$db_source = 'M'; + +if ($ignore_afterhours=="checked") {$status_clause=" and status!='AFTHRS'";} + +$HTML_text=""; +$report_display_type="HTML"; + +# $actual_agents=preg_replace("/[^0-9.]/", "", $actual_agents); +# $actual_agents+=0; +# $hourly_pay=preg_replace("/[^0-9.]/", "", $hourly_pay); +# $hourly_pay+=0; +# $revenue_per_sale=preg_replace("/[^0-9.]/", "", $revenue_per_sale); +# $revenue_per_sale+=0; +# $sale_chance=preg_replace("/[^0-9.]/", "", $sale_chance); +# $sale_chance+=0; +# $retry_rate=preg_replace("/[^0-9.]/", "", $retry_rate); +# $retry_rate+=0; + +switch ($erlang_type) { + default: + case "B": + $erlB="checked"; + $erlC=""; + break; + case "C": + $erlB=""; + $erlC="checked"; + break; +} + +$JS_text="\n"; +$HEADER.=""; + +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +# $HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.=""._QXZ("$report_name")."\n"; + +$short_header=1; + +$MAIN.="
\n"; +$MAIN.=""._QXZ("$report_name")." $NWB#inbound_forecasting$NWE\n"; + +#$MAIN.="\n"; +$MAIN.="\n"; + +$MAIN.="\n"; + +$MAIN.="\n"; +# $MAIN.="\n"; +$MAIN.="
"._QXZ("Dates").":
"; +$MAIN.="\n"; + + +$MAIN.=""; + +$MAIN.="\n"; + +$MAIN.="
"._QXZ("to")."
"; + +$MAIN.="

"; +$MAIN.=""._QXZ("Target drop rate").":
% ("._QXZ("optional").")"; +# $MAIN.=""._QXZ("Target queue prob.").":% (C report)"; +$MAIN.="
"._QXZ("Campaigns").":
"; +$MAIN.="\n"; +$MAIN.="
"._QXZ("In-groups").":
\n"; +$MAIN.="
"._QXZ("Cost analysis stats (optional)").":
"; +# $MAIN.=_QXZ("Actual agents").":

"; +# $MAIN.=_QXZ("Hourly pay per agent").":
\$
"; +# $MAIN.=_QXZ("Revenue per sale").":
\$
"; +# $MAIN.=_QXZ("Chance of sale").":
%
"; +# $MAIN.=_QXZ("Retry rate").":
% (B "._QXZ("reports only").")"; +# $MAIN.="
"; +$MAIN.=""; +$MAIN.=""; + +# $MAIN.=""._QXZ("Erlang type").":
"; +# $MAIN.="B - "._QXZ("inbound/call loss stats")."
"; +# $MAIN.="C - "._QXZ("outbound/waiting time stats")."

"; + +# $MAIN.="  "; + + +if ($IDR_calltime_available==1) + { + $MAIN.="\n"; + } + +$MAIN.="


"._QXZ("Advanced Forecasting Report")."

"._QXZ("DOWNLOAD")." | "._QXZ("REPORTS")."
\n"; +# $MAIN.="
"; +$MAIN.="
";
+
+if ($groups_selected==0 && $campaigns_selected==0)
+	{
+	$MAIN.="\n\n";
+	$MAIN.=_QXZ("PLEASE SELECT AN IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT")."\n";
+	echo "$HEADER";
+	require("admin_header.php");
+	echo "$MAIN";
+	}
+else
+	{
+	$campaign_group_stmt="select closer_campaigns from vicidial_campaigns where campaign_id in ($campaign_SQL)";
+	if ($DB) {echo "|$campaign_group_stmt|\n";}
+	$campaign_group_rslt=mysql_to_mysqli($campaign_group_stmt, $link);
+	$campaign_group_SQL="";
+	while ($cg_row=mysqli_fetch_row($campaign_group_rslt)) {
+		if (strlen(trim($cg_row[0]))>0) {
+			$cg_row[0]=preg_replace("/^\s+|\s\-/", "", $cg_row[0]);
+			$campaign_group_SQL.="'".preg_replace("/\s/", "','", $cg_row[0])."',";
+		}		
+	}
+	$campaign_group_SQL=$group_SQL.",".$campaign_group_SQL;
+	$campaign_group_SQL=preg_replace("/^,|,$/", "", $campaign_group_SQL);
+
+	$campaign_string=preg_replace("/^\||\|$/", "", $campaign_string);
+	$group_string=preg_replace("/^\||\|$/", "", $group_string);
+	$ASCII_text =" Date range :  $query_date to $end_date\n";
+	$ASCII_text.=" Campaigns  :  ".preg_replace("/\|/", ", ", $campaign_string)."\n";
+	$ASCII_text.=" In-groups  :  ".preg_replace("/\|/", ", ", $group_string)."\n\n";
+# 	$ASCII_text.=" Report type:  $erlang_type\n\n";
+
+	$HTML_text.=" Date range :  $query_date to $end_date\n";
+	$HTML_text.=" Campaigns  :  ".preg_replace("/\|/", ", ", $campaign_string)."\n";
+	$HTML_text.=" In-groups  :  ".preg_replace("/\|/", ", ", $group_string)."";
+# 	$HTML_text.=" Report type:  $erlang_type\n\n";
+	
+	$sale_stmt="select distinct status from vicidial_campaign_statuses where campaign_id in ($campaign_SQL) and sale='Y' UNION select status from vicidial_statuses where sale='Y'";
+	if ($DB) {echo "|$sale_stmt|\n";}
+	$sale_rslt=mysql_to_mysqli($sale_stmt, $link);
+	$sales_array=array();
+	while ($sale_row=mysqli_fetch_row($sale_rslt)) {
+		array_push($sales_array, "$sale_row[0]");
+	}
+
+	if ($erlang_type=="B") {
+		$hour_stmt="select closecallid, substr(call_date, 1, 13) as start_hour, length_in_sec, substr(call_date+INTERVAL length_in_sec second, 1, 13) as end_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'))-UNIX_TIMESTAMP(call_date), length_in_sec) as length_up_to_next_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(call_date+INTERVAL length_in_sec second)-UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00')), 0) as length_running_into_next_hour, status, uniqueid from vicidial_closer_log where length_in_sec is not null and campaign_id in ($campaign_group_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59' and status!='AFTHRS'"; # *
+
+		$avg_stmt="select avg(length_in_sec) as avg_length from vicidial_closer_log where length_in_sec is not null and campaign_id in ($campaign_group_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # **
+
+		$wrapup_stmt="select uniqueid from vicidial_closer_log where length_in_sec is not null and user!='VDCL' and campaign_id in ($campaign_group_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # ***
+	} else {
+		$hour_stmt="select uniqueid, substr(call_date, 1, 13) as start_hour, length_in_sec, substr(call_date+INTERVAL length_in_sec second, 1, 13) as end_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'))-UNIX_TIMESTAMP(call_date), length_in_sec) as length_up_to_next_hour, if(DATE_FORMAT(call_date, '%Y-%m-%d %H:00:00')!=DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00'), UNIX_TIMESTAMP(call_date+INTERVAL length_in_sec second)-UNIX_TIMESTAMP(DATE_FORMAT(call_date+INTERVAL length_in_sec second, '%Y-%m-%d %H:00:00')), 0) as length_running_into_next_hour, status, uniqueid from vicidial_log where length_in_sec is not null and campaign_id in ($campaign_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59' and status!='AFTHRS'"; # *
+
+		$avg_stmt="select avg(length_in_sec) as avg_length from vicidial_log where length_in_sec is not null and campaign_id in ($campaign_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # **
+
+		$wrapup_stmt="select uniqueid from vicidial_log where length_in_sec is not null and user!='VDCL' and campaign_id in ($campaign_SQL) and call_date>='$query_date 00:00:00' and call_date<='$end_date 23:59:59'"; # ***
+	}
+	if ($DB) {echo "|$hour_stmt|\n";}
+	if ($DB) {echo "|$avg_stmt|\n";}
+	if ($DB) {echo "|$wrapup_stmt|\n";}
+
+	# $ASCII_text.=$hour_stmt."
\n"; + $hour_rslt=mysql_to_mysqli($hour_stmt, $link); # * + $erlang_calls=mysqli_num_rows($hour_rslt); + + # PROVIDE ACTUAL STATS + $avg_rslt=mysql_to_mysqli($avg_stmt, $link); # ** + $avg_row=mysqli_fetch_array($avg_rslt); + $average_call_length=$avg_row["avg_length"]; + + $wrapup_rslt=mysql_to_mysqli($wrapup_stmt, $link); # *** + $wrapup_calls=mysqli_num_rows($wrapup_rslt); + $uid_ct=0; + $uid_clause=""; + $dispo_secs=0; + $talk_secs=0; + while ($wrapup_row=mysqli_fetch_row($wrapup_rslt)) { + $uid_ct++; + $uid_clause.="'$wrapup_row[0]',"; + if ($uid_ct%100==0) { + $uid_clause=preg_replace('/,$/', '', $uid_clause); + $uid_stmt="select dispo_sec, talk_sec from vicidial_agent_log where uniqueid in ($uid_clause)"; + $uid_rslt=mysql_to_mysqli($uid_stmt, $link); + while ($uid_row=mysqli_fetch_row($uid_rslt)) { + $dispo_secs+=$uid_row[0]; + $talk_secs+=$uid_row[1]; + } + $uid_clause=""; + } + } + if (strlen($uid_clause)>0) { + $uid_clause=preg_replace('/,$/', '', $uid_clause); + $uid_stmt="select dispo_sec, talk_sec from vicidial_agent_log where uniqueid in ($uid_clause)"; + $uid_rslt=mysql_to_mysqli($uid_stmt, $link); + while ($uid_row=mysqli_fetch_row($uid_rslt)) { + $dispo_secs+=$uid_row[0]; + $talk_secs+=$uid_row[1]; + } + $uid_clause=""; + } + $avg_dispo_sec=MathZDC($dispo_secs, $wrapup_calls); + $avg_talk_sec=MathZDC($talk_secs, $wrapup_calls); + ##### + + + $wrapup_stmt="select average(dispo_sec) from vicidial_agent_log"; + + $erlang_array=array(); + $drops_blocks=0; + $sales=0; + while ($hour_row=mysqli_fetch_array($hour_rslt)) { + $erlang_array["$hour_row[start_hour]"][0]+=$hour_row["length_up_to_next_hour"]; + $erlang_array["$hour_row[start_hour]"][2]++; + + if ($hour_row["length_running_into_next_hour"]>0) { + $erlang_array["$hour_row[end_hour]"][0]+=$hour_row["length_running_into_next_hour"]; + $erlang_array["$hour_row[end_hour]"][2]++; + if ($hour_row["status"]=="DROP") { + $erlang_array["$hour_row[end_hour]"][3]++; + } + } + + if ($hour_row["status"]=="DROP") { + $erlang_array["$hour_row[start_hour]"][1]+=$hour_row["length_up_to_next_hour"]; + $erlang_array["$hour_row[end_hour]"][1]+=$hour_row["length_running_into_next_hour"]; + $erlang_array["$hour_row[start_hour]"][3]++; + $drops_blocks++; + } + + if (in_array("$hour_row[status]", $sales_array)) { + $erlang_array["$hour_row[start_hour]"][4]++; + $sales++; + } + } + $hours_active=count($erlang_array); # Used for giving total erlangs for day, need to divide by number of hours reported, not one hour + $total_erlangs=MathZDC(($erlang_calls*$average_call_length),(3600*$hours_active)); + $total_blocking=MathZDC($drops_blocks, $erlang_calls); + $sale_percent=MathZDC($sales, $erlang_calls); + + $rpt_header ="+-----------------+-------+-------+------------+----------+-------------+----------+---------+"; + if ($erlang_type=="B") {$rpt_header.="---------+";} + if ($erlang_type=="C") {$rpt_header.="------------+------------+";} + $rpt_header.="------------+------------+------------+----------+-----------+------------+------------+------------+\n"; + + $ASCII_text.=$rpt_header; + # $ASCII_text.=$hour_stmt."
\n"; + + # Damn fixed-space formatting, hate ASCII. HATE. + if ($erlang_type=="B") { + if ($actual_agents>0) { + $ASCII_text.="| ".sprintf("%70s", _QXZ("Actual agents: ")).sprintf("%-131s", "$actual_agents")." |\n"; + } + $ASCII_text.="| ".sprintf("%70s", _QXZ("Total calls: ")).sprintf("%-131s", "$erlang_calls")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Total drops: ")).sprintf("%-131s", "$drops_blocks")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired drop rate: ")).sprintf("%-5.2f", "$drop_percent").sprintf("%-126s", " %")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Total blocking/drop rate: ")).sprintf("%-5.2f", (100*$total_blocking)).sprintf("%-126s", " %")." |\n"; # sprintf("%-131.4f", "$total_blocking") + # $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired sale rate: ")).sprintf("%-5.2f", "$sale_chance").sprintf("%-126s", " %")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Sale rate: ")).sprintf("%-5.2f", (100*$sale_percent)).sprintf("%-126s", " %")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Average call duration: ")).sprintf("%-131.2f", "$average_call_length")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Erlangs: ")).sprintf("%-131.4f", $total_erlangs)." |\n"; + } + if ($erlang_type=="C") { + if ($actual_agents>0) { + $ASCII_text.="| ".sprintf("%70s", _QXZ("Actual agents: ")).sprintf("%-147s", "$actual_agents")." |\n"; + } + $ASCII_text.="| ".sprintf("%70s", _QXZ("Total calls: ")).sprintf("%-147s", "$erlang_calls")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Total drops: ")).sprintf("%-147s", "$drops_blocks")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired drop rate: ")).sprintf("%-5.2f", "$drop_percent").sprintf("%-142s", " %")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Total blocking/drop rate: ")).sprintf("%-5.2f", (100*$total_blocking)).sprintf("%-142s", " %")." |\n"; # sprintf("%-147.4f", "$total_blocking") + # $ASCII_text.="| ".sprintf("%70s", _QXZ("Desired sale rate: ")).sprintf("%-5.2f", "$sale_chance").sprintf("%-142s", " %")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Sale rate: ")).sprintf("%-5.2f", (100*$sale_percent)).sprintf("%-142s", " %")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Average call duration: ")).sprintf("%-147.2f", "$average_call_length")." |\n"; + $ASCII_text.="| ".sprintf("%70s", _QXZ("Erlangs: ")).sprintf("%-147.4f", $total_erlangs)." |\n"; + } + + $HTML_text.=""; + $HTML_text.=""; # B +# $HTML_text.=""; # B + } + if ($erlang_type=="C") { + $HTML_text.=""; # C + $HTML_text.=""; # C + } +# $HTML_text.=""; + ############# + + ##### RECOMMENDED AGENTS + $lines=1; + if ($erlang_type=="B") { + $GoS=MathZDC((pow($total_erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $total_erlangs))); + if ($GoS>$drop_rate) { + $ASCII_text.=""; + } + } + if ($erlang_type=="C") { + $Pqueue=(pow($total_erlangs, $lines)/(factorial($lines)))/((pow($total_erlangs, $lines)/(factorial($lines)))+((1-MathZDC($total_erlangs, $lines))*erlsum(0, ($lines-1), $total_erlangs))); + if ($Pqueue>$pqueue_target) { + $ASCII_text.=""; + } + } + + if ($erlang_type=="B") { + $ASCII_text.="| ".sprintf("%70s", _QXZ("Recommended agent count: ")).sprintf("%-131s", $lines)." |\n"; + } else { + $ASCII_text.="| ".sprintf("%70s", _QXZ("Recommended agent count: ")).sprintf("%-147s", $lines)." |\n"; + } + $CSV_text.="\"Recommended agent count:\",\"$lines\"\n"; + $CSV_text.="\n"; + ############# + + $ASCII_text.=$rpt_header; + $ASCII_text.= "| "._QXZ("CALLING HOUR", 15)." | "._QXZ("CALLS", 5)." | "._QXZ("SALES", 5)." | "._QXZ("TOTAL TIME", 10)." | "._QXZ("AVG TIME", 8)." | "._QXZ("DROPPED HRS", 11)." | "._QXZ("BLOCKING", 8)." | "._QXZ("ERLANGS", 7); + if ($erlang_type=="B") {$ASCII_text.=" | "._QXZ("GOS", 7);} # B + if ($erlang_type=="C") {$ASCII_text.=" | "._QXZ("QUEUE PROB", 10)." | "._QXZ("AVG ANSWER", 10);} # C + $ASCII_text.=" | "._QXZ("REC AGENTS", 10)." | "._QXZ("EST AGENTS", 10)." | "._QXZ("CALLS/AGNT", 10)." |\n"; # ." | "._QXZ("REV/CALL", 8)." | "._QXZ("REV/AGENT", 9)." | "._QXZ("TOTAL REV", 10)." | "._QXZ("TOTAL COST", 10)." | "._QXZ("MARGIN", 10) + $ASCII_text.=$rpt_header; + $CSV_text.="\""._QXZ("CALLING HOUR")."\",\""._QXZ("CALLS")."\",\""._QXZ("SALES")."\",\""._QXZ("TOTAL TIME")."\",\""._QXZ("AVG TIME")."\",\""._QXZ("DROPPED HRS")."\",\""._QXZ("BLOCKING")."\",\""._QXZ("ERLANGS")."\","; + if ($erlang_type=="B") {$CSV_text.="\""._QXZ("GRADE OF SERVICE")."\",";} # B + if ($erlang_type=="C") {$CSV_text.="\""._QXZ("QUEUE PROBABILITY")."\",\""._QXZ("AVERAGE ANSWER SPEED")."\",";} # C + $CSV_text.="\""._QXZ("REC AGENTS")."\",\""._QXZ("EST AGENTS")."\",\""._QXZ("CALLS/AGNT")."\"\n"; # ,\""._QXZ("REV/CALL")."\",\""._QXZ("REV/AGENT")."\",\""._QXZ("TOTAL REV")."\",\""._QXZ("TOTAL COST")."\",\""._QXZ("MARGIN")."\" + ksort($erlang_array); + + $HTML_text2=""; + $HTML_text2.="
"; + + $CSV_text=""; + if ($actual_agents>0) { + $CSV_text.="\"Actual agents:\",\"$actual_agents\"\n"; + } + $CSV_text.="\"Total calls:\",\"$erlang_calls\"\n"; + $CSV_text.="\"Total drops:\",\"$drops_blocks\"\n"; + $CSV_text.="\"Desired drop rate:\",\"".sprintf("%5.2f", "$drop_percent")." %\"\n"; + $CSV_text.="\"Total blocking/drop rate:\",\"".sprintf("%-5.2f", (100*$total_blocking))."\"\n"; + # $CSV_text.="\"Desired sale rate:\",\"".sprintf("%5.2f", "$sale_chance")." %\"\n"; + $CSV_text.="\"Sale rate:\",\"".sprintf("%-5.2f", (100*$sale_percent))."\"\n"; + $CSV_text.="\"Average call duration:\",\"".sprintf("%.2f", "$average_call_length")." seconds\"\n"; + $CSV_text.="\"Erlangs:\",\"".sprintf("%.4f", "$total_erlangs")."\"\n"; + + + # ESTIMATED AGENTS + $lines=1; + if ($total_blocking>0) { + $GoS=MathZDC((pow($total_erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $total_erlangs))); + if ($GoS>$total_blocking) { + $ASCII_text.=""; + } + $Pqueue=(pow($total_erlangs, $lines)/(factorial($lines)))/((pow($total_erlangs, $lines)/(factorial($lines)))+((1-MathZDC($total_erlangs, $lines))*erlsum(0, ($lines-1), $total_erlangs))); + $ASA=MathZDC(($Pqueue*$average_call_length), ($lines-$total_erlangs)); + } else { + $lines="N/A"; + $Pqueue=0; + $ASA=0; + } + if ($Pqueue>1) {$Pqueue=1;} + $est_GoS=$GoS; # Need this here since we moved the output line further down & need to save it. + $est_lines=$lines; # Need this here since we moved the output line further down & need to save it. + + if ($erlang_type=="B") { +# $ASCII_text.="| ".sprintf("%70s", _QXZ("Retry rate: ")).sprintf("%-131s", "$retry_rate %")." |\n"; # B + $ASCII_text.="| ".sprintf("%70s", _QXZ("Grade of service: ")).sprintf("%-131s", sprintf("%0.2f", (100*$GoS)." %"))." |\n"; # B + $ASCII_text.="| ".sprintf("%70s", _QXZ("Estimated agents fielding calls: ")).sprintf("%-131s", $lines)." |\n"; + } + if ($erlang_type=="C") { + $ASCII_text.="| ".sprintf("%70s", _QXZ("Estimated queue probability: ")).sprintf("%-5.2f", (100*$Pqueue)).sprintf("%-142s", " %")." |\n"; # C + $ASCII_text.="| ".sprintf("%70s", _QXZ("Average speed of answering: ")).sprintf("%-147s", sec_convert($ASA,'H'))." |\n"; # C + $ASCII_text.="| ".sprintf("%70s", _QXZ("Estimated agents fielding calls: ")).sprintf("%-147s", $lines)." |\n"; + } + + if ($erlang_type=="B") { +# $CSV_text.="\""._QXZ("Retry rate: ")."\",\"$retry_rate %\"\n"; # B + $CSV_text.="\""._QXZ("Grade of service: ")."\",\"".sprintf("%0.2f", (100*$GoS))." %\"\n"; # B + } + if ($erlang_type=="C") { + $CSV_text.="\""._QXZ("Estimated queue probability: ")."\",\"".sprintf("%.2f", (100*$Pqueue))."%\"\n"; # C + $CSV_text.="\""._QXZ("Average speed of answering: ")."\",\"".sec_convert($ASA,'H')."\"\n"; # C + } + $CSV_text.="\""._QXZ("Estimated agents fielding calls: ")."\",\"$lines\"\n"; + + if ($erlang_type=="B") { +## $HTML_text.="
"._QXZ("Retry rate: ")."$retry_rate %
"._QXZ("Grade of service: ")."".sprintf("%0.2f", (100*$GoS))."%
"._QXZ("Estimated queue probability: ")."".sprintf("%.2f", (100*$Pqueue))."%
"._QXZ("Average speed of answering: ")."".sec_convert($ASA,'H')."
"._QXZ("Estimated agents fielding calls: ")."".$lines."
"; + $HTML_text2.="
"; + $HTML_text2.=""; + if ($actual_agents>0) { + $HTML_text2.=""; + } + $HTML_text2.=""; + $HTML_text2.=""; + $HTML_text2.=""; + $HTML_text2.=""; + # $HTML_text2.=""; + $HTML_text2.=""; + $HTML_text2.=""; + $HTML_text2.=""; + $HTML_text2.=""; # B + $HTML_text2.=""; + $HTML_text2.=""; + $HTML_text2.="
"._QXZ("INBOUND SUMMARY")."
"._QXZ("Actual agents: ")."".$actual_agents."
"._QXZ("Total calls: ")."".$erlang_calls."
"._QXZ("Total drops: ")."".$drops_blocks."
"._QXZ("Desired drop rate: ")."".sprintf("%5.2f", "$drop_percent")." %
"._QXZ("Total blocking/drop rate: ")."".sprintf("%-5.2f", (100*$total_blocking))." %
"._QXZ("Desired sale rate: ")."".sprintf("%5.2f", "$sale_chance")." %
"._QXZ("Sale rate: ")."".sprintf("%-5.2f", (100*$sale_percent))." %
"._QXZ("Average call duration: ")."".sprintf("%18.2f", "$average_call_length")."
"._QXZ("Erlangs: ")."".sprintf("%18.4f", $total_erlangs)."
"._QXZ("Grade of service: ")."".sprintf("%0.2f", (100*$est_GoS))."%
"._QXZ("Estimated agents fielding calls: ")."".$est_lines."
"._QXZ("Recommended agent count: ")."".$lines."
"; + $HTML_text2.="
"; # For closing the table above that encompasses first report table and chart + + $HTML_text2.=""; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + + if ($erlang_type=="B") { + $HTML_text2.="\n"; # B + } + if ($erlang_type=="C") { + $HTML_text2.="\n"; # C + $HTML_text2.="\n"; # C + } + + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + # $HTML_text2.="\n"; + # $HTML_text2.="\n"; + # $HTML_text2.="\n"; + # $HTML_text2.="\n"; + # $HTML_text2.="\n"; + $HTML_text2.="\n"; + + + $bht=0; + $graph_stats=array(); + $q=0; +# while(list($key, $val)=each($erlang_array)) { + foreach($erlang_array as $key => $val) { + if ($val[0]>$bht) {$bht=$val[0];} + if ($q%2==0) {$tdclass="records_list_x";} else {$tdclass="records_list_y";} + $average_time=round(MathZDC($val[0], $val[2])); + $blocking=MathZDC($val[3], $val[2]); + $erlangs=$val[2]*MathZDC($average_time, 3600); # Row is call per hour, therefore call length average must be in hours. + $sales=$val[4]+0; + + $ASCII_text.="| "; #.substr($key, 0, -2)." - ".substr($key, 5, 2)." ".substr($key, 8, 2)." ".substr($key, 0, 4); + $ASCII_text.=date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4))); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%5s", $val[2]); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%5s", $sales); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%10s", sec_convert($val[0],'H')); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%8s", sec_convert($average_time,'H')); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%11s", sec_convert($val[1],'H')); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%8s", sprintf("%01.4f", $blocking)); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%7s", sprintf("%01.4f", $erlangs)); + $ASCII_text.=" | "; + + $CSV_text.="\"".date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4)))."\",\"".$val[2]."\",\"".$sales."\",\"".sec_convert($val[0],'H')."\",\"".sec_convert($average_time,'H')."\",\"".sec_convert($val[1],'H')."\",\"".sprintf("%01.4f", $blocking)."\",\"".sprintf("%01.4f", $erlangs)."\","; + + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + $HTML_text2.="\n"; + + $graph_key=date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4))); + $graph_stats["$graph_key"][0]=$val[2]; + $graph_stats["$graph_key"][1]=$val[0]; + $graph_stats["$graph_key"][2]=$average_time; + $graph_stats["$graph_key"][3]=$val[1]; + $graph_stats["$graph_key"][4]=sprintf("%01.4f", $blocking); + $graph_stats["$graph_key"][5]=sprintf("%01.4f", $erlangs); + + ##### RECOMMENDED AGENTS + $lines=1; + if ($erlang_type=="B") { + $GoS=MathZDC((pow($erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $erlangs))); + if ($GoS>$drop_rate) { + $ASCII_text.=""; + } + } + if ($erlang_type=="C") { + $Pqueue=(pow($erlangs, $lines)/(factorial($lines)))/((pow($erlangs, $lines)/(factorial($lines)))+((1-MathZDC($erlangs, $lines))*erlsum(0, ($lines-1), $erlangs))); + if ($Pqueue>$pqueue_target) { + $ASCII_text.=""; + } + } + $recommended_agents=$lines; + + ##### ESTIMATED AGENTS + $lines=1; + if ($blocking>0) { + $GoS=MathZDC((pow($erlangs, $lines)/(factorial($lines))), (erlsum(0, $lines, $erlangs))); + if ($GoS>$blocking) { + $ASCII_text.=""; + } + + $Pqueue=(pow($erlangs, $lines)/(factorial($lines)))/((pow($erlangs, $lines)/(factorial($lines)))+((1-MathZDC($erlangs, $lines))*erlsum(0, ($lines-1), $erlangs))); + $ASA=MathZDC(($Pqueue*$average_time), ($lines-$erlangs)); + } else { + $lines="$recommended_agents"; + $Pqueue=0; + $ASA=0; + } + if ($actual_agents>0) { + $lines=$actual_agents; + $Pqueue=0; + $ASA=0; + } + if ($Pqueue>1) {$Pqueue=1;} + + if ($erlang_type=="B") { + $ASCII_text.=sprintf("%7s", sprintf("%0.2f", (100*$GoS))."%"); + $ASCII_text.=" | "; + } + if ($erlang_type=="C") { + $ASCII_text.=sprintf("%10s", sprintf("%.4f", (100*$Pqueue))."%"); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%10s", sec_convert($ASA,'H')); + $ASCII_text.=" | "; + } + $ASCII_text.=sprintf("%10s", $recommended_agents); + $ASCII_text.=" | "; + if ($erlang_type=="B") { + $CSV_text.="\"".sprintf("%0.2f", (100*$GoS))."%\","; # B + } + if ($erlang_type=="C") { + $CSV_text.="\"".sprintf("%.6f", (100*$Pqueue))."%\","; # C + $CSV_text.="\"".sec_convert($ASA,'H')."\","; # C + } + $CSV_text.="\"$recommended_agents\","; + $graph_stats["$graph_key"][7]=$recommended_agents; + if ($erlang_type=="B") { + $HTML_text2.="\n"; # B + } + if ($erlang_type=="C") { + $HTML_text2.="\n"; # C + $HTML_text2.="\n"; # C + } + $HTML_text2.="\n"; + + $ASCII_text.=sprintf("%10s", $lines); + $ASCII_text.=" | "; + $ASCII_text.=sprintf("%-10.2f", MathZDC($val[2], $lines)); +# $ASCII_text.=" | "; +# $ASCII_text.=sprintf("%-8s", "\$".number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",",")); +# $ASCII_text.=" | "; +# $ASCII_text.=sprintf("%-9s", "\$".number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",",")); +# $ASCII_text.=" | "; +# $ASCII_text.=sprintf("%-10s", "\$".number_format(($revenue_per_sale*$sales),2,".",",")); +# $ASCII_text.=" | "; +# $ASCII_text.=sprintf("%-10s", "\$".number_format(($lines*$hourly_pay),2,".",",")); +# $ASCII_text.=" | "; +# $ASCII_text.=sprintf("%-10s", "\$".number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",",")); + $ASCII_text.=" |\n"; + + $graph_stats["$graph_key"][8]=$drop_rate; + + + $CSV_text.="\"$lines\","; + $CSV_text.="\"".sprintf("%.2f", MathZDC($val[2], $lines))."\","; +# $CSV_text.="\"$".number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",",")."\","; +# $CSV_text.="\"$".number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",",")."\","; +# $CSV_text.="\"$".number_format(($revenue_per_sale*$sales),2,".",",")."\","; +# $CSV_text.="\"$".number_format(($lines*$hourly_pay),2,".",",")."\","; +# $CSV_text.="\"$".number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",",")."\"\n"; + + $graph_stats["$graph_key"][6]=$lines; + $graph_stats["$graph_key"][8]=$drop_rate; + $graph_stats["$graph_key"][9]=$sales; + $graph_stats["$graph_key"][10]=number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",""); # Revenue per call + $graph_stats["$graph_key"][11]=number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",""); # Revenue per agent + $graph_stats["$graph_key"][12]=number_format(($revenue_per_sale*$sales),2,".",""); # Total revenue + $graph_stats["$graph_key"][13]=number_format(($lines*$hourly_pay),2,".",""); # Cost + $graph_stats["$graph_key"][14]=number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",","); + $graph_stats["$graph_key"][15]=$GoS; + $graph_stats["$graph_key"][16]=$Pqueue; # Cost + $graph_stats["$graph_key"][17]=$ASA; # Cost + + $HTML_text2.="\n"; + $HTML_text2.="\n"; +# $HTML_text2.="\n"; +# $HTML_text2.="\n"; +# $HTML_text2.="\n"; +# $HTML_text2.="\n"; +# $HTML_text2.="\n"; + $HTML_text2.="\n"; + $q++; + } + $ASCII_text.=$rpt_header; + $ASCII_text.=" BHT: ".sec_convert($bht,'H')." ($bht seconds)\n"; + + $HTML_text2.="
"._QXZ("CALLING HOUR").""._QXZ("CALLS").""._QXZ("SALES").""._QXZ("TOTAL TIME").""._QXZ("AVG TIME").""._QXZ("DROPPED HRS").""._QXZ("BLOCKING").""._QXZ("ERLANGS").""._QXZ("GRADE OF SERVICE").""._QXZ("QUEUE PROB").""._QXZ("AVG ANSWER").""._QXZ("REC AGENTS").""._QXZ("EST AGENTS").""._QXZ("CALLS PER AGENT").""._QXZ("REVENUE PER CALL").""._QXZ("REVENUE PER AGENT").""._QXZ("TOTAL REVENUE").""._QXZ("TOTAL COST").""._QXZ("MARGIN")."
".date("Y-m-d ha", mktime(substr($key, -2), 0, 0, substr($key, 5, 2), substr($key, 8, 2), substr($key, 0, 4)))."".$val[2]."".$sales."".sec_convert($val[0],'H')."".sec_convert($average_time,'H')."".sec_convert($val[1],'H')."".sprintf("%01.4f", $blocking)."".sprintf("%01.4f", $erlangs)."".sprintf("%0.2f", (100*$GoS))."%".sprintf("%.4f", (100*$Pqueue))."%".sec_convert($ASA,'H')." $recommended_agents$lines".sprintf("%.2f", ($val[2]/$lines))."\$".number_format(MathZDC(($revenue_per_sale*$sales), $val[2]),2,".",",")."\$".number_format(MathZDC(($revenue_per_sale*$sales), $lines),2,".",",")."\$".number_format(($revenue_per_sale*$sales),2,".",",")."\$".number_format(($lines*$hourly_pay),2,".",",")."\$".number_format((($revenue_per_sale*$sales)-($lines*$hourly_pay)),2,".",",")."
"; + + # USE THIS FOR COMBINED graphs, use pipe-delimited array elements, dataset_name|index|link_name|graph_override + # You have to hard code the graph name in where it is overridden and mind the data indices. No other way to do it. + $multigraph_text=""; + $graph_id++; + $graph_array=array("ERL_AGENTSdata|7,6|AGENTS|integer|Rec. Agents,Est. Agents", "ERL_BLOCKdata|4,8|BLOCKING/DROPS|percent|Blocking,Desired drop rate", "ERL_CALLSdata|0,9|CALLS|integer|Calls,Sales", "ERL_TIMEdata|2,3,1|TIMES|time|Average time,Dropped time,Total time", "ERL_ERLANGSdata|5|ERLANGS|integer|Erlangs"); # , "ERL_REVENUEdata|10,11|REVENUE|dollar|Revenue per call,Revenue per agent", "ERL_REVENUEdata|12,13|MARGINS|dollar|Total revenue,Total cost" + if ($erlang_type=="B") { + array_push($graph_array, "ERL_GOSdata|15|GoS|integer|Grade of Service"); + } + if ($erlang_type=="C") { + array_push($graph_array, "ERL_PQUEUEdata|16|QUEUE|percent|Call queue probability"); + } + + + $default_graph="line"; # Graph that is initally displayed when page loads + include("graph_color_schemas.inc"); + + + # CUSTOMIZING COLORS FOR LINE GRAPHS + $graph_colors=array("216,0,0", "0,0,216", "0,216,0", "216,216,0", "216,0,216", "0,216,216"); + + + $graph_totals_array=array(); + $graph_totals_rawdata=array(); + for ($q=0; $q $val) { + $labels.="\"".preg_replace('/ +/', ' ', $key)."\","; + } + reset($graph_stats); + $labels=preg_replace('/,$/', '', $labels)."],\n"; + + for ($d=0; $d $val) { + $val[$dataset_index]=preg_replace("/N\/A/", "0", $val[$dataset_index]); + $data.="\"".$val[$dataset_index]."\","; + $current_graph_total+=intval($val[$dataset_index]); + $bgcolor=$backgroundColor[($d%count($backgroundColor))]; + $hbgcolor=$hoverBackgroundColor[($d%count($hoverBackgroundColor))]; + $hbcolor=$hoverBorderColor[($d%count($hoverBorderColor))]; + } + reset($graph_stats); + $data=preg_replace('/,$/', '', $data)."],\n"; + $datasets.=$data; + $datasets.=$graphConstantsA.$graphConstantsB.$graphConstantsC; # SEE TOP OF SCRIPT + $datasets.="\t\t\t},\n"; + $graph_totals_rawdata[$d]=$current_graph_total; + } + $datasets=preg_replace('/,\n$/', "\n", $datasets); + + switch($dataset_type) { + case "time": + $chart_options="options: {tooltips: {callbacks: {label: function(tooltipItem, data) {var value = Math.round(data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]); return data.datasets[tooltipItem.datasetIndex].label+\": \"+value.toHHMMSS();}}}, legend: { display: true }},"; + break; + case "percent": + $chart_options="options: {tooltips: {callbacks: {label: function(tooltipItem, data) {var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; return data.datasets[tooltipItem.datasetIndex].label+\": \"+ (value*100) + '%';}}}, legend: { display: true }},"; + break; + case "dollar": + $chart_options="options: {tooltips: {callbacks: {label: function(tooltipItem, data) {var value = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index]; return data.datasets[tooltipItem.datasetIndex].label+\": \$\"+ value;}}}, legend: { display: true }},"; + break; + default: + $chart_options="options: { legend: { display: true}},"; + break; + } + + $datasets.="\t\t]\n"; + $datasets.="\t}\n"; + + $JS_text.=$labels.$datasets; + $JS_text.="var main_ctx = document.getElementById(\"CanvasID".$graph_id."_".$q."\");\n"; + $JS_text.="var GraphID".$graph_id."_".$q." = new Chart(main_ctx, {type: '$default_graph', $chart_options data: $dataset_name});\n"; + } + + + $graph_count=count($graph_array); + $graph_title=_QXZ("FORECASTING REPORT"); + $hide_graph_choice="yes"; + $override_width=900; $override_height=500; + include("graphcanvas.inc"); + $HEADER.=$HTML_graph_head; + $GRAPH.=$graphCanvas; + + + if ($report_display_type=="HTML") + { + $JS_onload.="}\n"; + $JS_text.=$JS_onload; + $JS_text.="\n"; + require("chart_button.php"); + + $MAIN.=$HTML_text.$GRAPH.$HTML_text2.$JS_text; + } + else + { + $MAIN.=$ASCII_text; + } + + + $MAIN.=""; + +if ($file_download>0) + { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_Erlang_report_$US$FILE_TIME.csv"; + $CSV_text=preg_replace('/\n +,/', ',', $CSV_text); + $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); + $CSV_text=preg_replace('/\" +/', '"', $CSV_text); + + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + } +else + { + header("Content-type: text/html; charset=utf-8"); + + echo "$HEADER"; + require("admin_header.php"); + echo "$MAIN"; + flush(); + } +# echo $ASCII_text; + } ?> \ No newline at end of file diff --git a/agc_2-X/trunk/www/vicidial/AST_source_vlc_status_report.php b/agc_2-X/trunk/www/vicidial/AST_source_vlc_status_report.php index c6934184..cf29d3be 100644 --- a/agc_2-X/trunk/www/vicidial/AST_source_vlc_status_report.php +++ b/agc_2-X/trunk/www/vicidial/AST_source_vlc_status_report.php @@ -1,663 +1,663 @@ - LICENSE: AGPLv2 -# -# CHANGES -# -# 180211-1111 - First build -# 180214-2230 - Added column to download for VLC or source_id -# 180507-2315 - Added new help display -# 191013-0834 - Fixes for PHP7 -# - -$startMS = microtime(); - -require("dbconnect_mysqli.php"); -require("functions.php"); - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} - elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} -if (isset($_GET["end_date_D"])) {$end_date_D=$_GET["end_date_D"];} - elseif (isset($_POST["end_date_D"])) {$end_date_D=$_POST["end_date_D"];} -if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} - elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} -if (isset($_GET["end_date_T"])) {$end_date_T=$_GET["end_date_T"];} - elseif (isset($_POST["end_date_T"])) {$end_date_T=$_POST["end_date_T"];} -if (isset($_GET["group"])) {$group=$_GET["group"];} - elseif (isset($_POST["group"])) {$group=$_POST["group"];} -if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} - elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} -if (isset($_GET["group_by"])) {$group_by=$_GET["group_by"];} - elseif (isset($_POST["group_by"])) {$group_by=$_POST["group_by"];} -if (isset($_GET["sort_by"])) {$sort_by=$_GET["sort_by"];} - elseif (isset($_POST["sort_by"])) {$sort_by=$_POST["sort_by"];} -if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} - elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} -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"];} - -$report_name="Outbound Lead Source Report"; -$NOW_DATE = date("Y-m-d"); -if (!isset($group)) {$group=array();} -if (!isset($query_date_D)) {$query_date_D=$NOW_DATE;} -if (!isset($end_date_D)) {$end_date_D=$NOW_DATE;} -if (!isset($query_date_T)) {$query_date_T="00:00:00";} -if (!isset($end_date_T)) {$end_date_T="23:59:59";} - -############################################# -##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $non_latin = $row[0]; - $outbound_autodial_active = $row[1]; - $slave_db_server = $row[2]; - $reports_use_slave_db = $row[3]; - $SSenable_languages = $row[4]; - $SSlanguage_method = $row[5]; - $SSreport_default_format = $row[6]; - } -##### END SETTINGS LOOKUP ##### -########################################### -if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} - -### ARCHIVED DATA CHECK CONFIGURATION -$archives_available="N"; -$log_tables_array=array("vicidial_list"); -for ($t=0; $t 0) - { - $row=mysqli_fetch_row($rslt); - $VUselected_language = $row[0]; - } - -$auth=0; -$reports_auth=0; -$admin_auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth > 0) - { - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $admin_auth=$row[0]; - - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $reports_auth=$row[0]; - - if ($reports_auth < 1) - { - $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ( ($reports_auth > 0) and ($admin_auth < 1) ) - { - $ADD=999999; - $reports_only_user=1; - } - } -else - { - $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ($auth_message == 'IPBLOCK') - { - $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - -##### BEGIN log visit to the vicidial_report_log table ##### -$LOGip = getenv("REMOTE_ADDR"); -$LOGbrowser = getenv("HTTP_USER_AGENT"); -$LOGscript_name = getenv("SCRIPT_NAME"); -$LOGserver_name = getenv("SERVER_NAME"); -$LOGserver_port = getenv("SERVER_PORT"); -$LOGrequest_uri = getenv("REQUEST_URI"); -$LOGhttp_referer = getenv("HTTP_REFERER"); -$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); -$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); -$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); -if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} -else {$LOGserver_port = ":$LOGserver_port";} -$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; - -$LOGhostname = php_uname('n'); -if (strlen($LOGhostname)<1) {$LOGhostname='X';} -if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} - -$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$webserver_id_ct = mysqli_num_rows($rslt); -if ($webserver_id_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $webserver_id = $row[0]; - } -else - { - ##### insert webserver entry - $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $affected_rows = mysqli_affected_rows($link); - $webserver_id = mysqli_insert_id($link); - } - -$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$report_log_id = mysqli_insert_id($link); -##### END log visit to the vicidial_report_log table ##### - -if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) - { - mysqli_close($link); - $use_slave_server=1; - $db_source = 'S'; - require("dbconnect_mysqli.php"); - $HTML_text.="\n"; - } - -$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; -if ($DB) {$HTML_text.="|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGuser_group = $row[0]; - -$stmt="SELECT allowed_campaigns,allowed_reports from vicidial_user_groups where user_group='$LOGuser_group';"; -if ($DB) {$HTML_text.="|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGallowed_campaigns = $row[0]; -$LOGallowed_reports = $row[1]; - -if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) - { - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; - exit; - } - -$LOGallowed_campaignsSQL=''; -$whereLOGallowed_campaignsSQL=''; -if ( (!preg_match("/-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')"; - } -$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - $group_string .= "$group[$i]|"; - $i++; - } - -$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$campaigns_to_print = mysqli_num_rows($rslt); -$i=0; -$groups=array(); -while ($i < $campaigns_to_print) - { - $row=mysqli_fetch_row($rslt); - $groups[$i] =$row[0]; - if (preg_match("/-ALL/",$group_string) ) - {$group[$i] = $groups[$i];} - $i++; - } - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) - { - $group_string .= "$group[$i]|"; - $group_SQL .= "'$group[$i]',"; - $groupQS .= "&group[]=$group[$i]"; - } - $i++; - } - -if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) - {$group_SQL = "";} -else - { - $group_SQL = preg_replace("/,\$/",'',$group_SQL); - $group_SQL_str=$group_SQL; - $group_SQL = "and campaign_id IN($group_SQL)"; - } - -$query_date="$query_date_D $query_date_T"; -$end_date="$end_date_D $end_date_T"; - -require("screen_colors.php"); - -# $NWB = "   \"HELP\""; - -$NWB = "\"HELP\""; - -$HTML_head.="\n"; -$HTML_head.="\n"; -$HTML_head.="\n"; - -$HTML_head.="\n"; -$HTML_head.="\n"; -$HTML_head.=""; - -$HTML_head.="\n"; -$HTML_head.="\n"; -$HTML_head.="\n"; -require("chart_button.php"); -$HTML_head.="\n"; -$HTML_head.="\n"; - -$HTML_head.="\n"; -$HTML_head.=""._QXZ("$report_name")."$group_S\n"; -$short_header=1; - -# require("admin_header.php"); - -$HTML_text.="
"; -$HTML_text.=""._QXZ("$report_name")." $NWB#source_vlc_status_report$NWE\n"; - -$HTML_text.="
\n"; -$HTML_text.="
"._QXZ("Entry date").":
"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.="\n"; -$HTML_text.=""; - -$HTML_text.="\n"; - -$HTML_text.="   "; - -$HTML_text.="
"._QXZ("to")."
"; - -$HTML_text.="\n"; - -$HTML_text.="   "; - -$HTML_text.="
"._QXZ("Campaign").":
"; -$HTML_text.="

\n"; - -$HTML_text.=_QXZ("Group by").":
"; -$HTML_text.="\n"; - -$HTML_text.="
 \n"; -$HTML_text.="\n"; -$HTML_text.=_QXZ("Display as").":
"; -$HTML_text.="\n

"; - -if ($archives_available=="Y") - { - $HTML_text.=""._QXZ("Search archived data")."\n"; - } - -$HTML_text.="

\n"; - -$HTML_text.="
"; - -$report_URL="$PHP_SELF?DB=$DB&query_date=$query_date&end_date=$end_date&query_date_D=$query_date_D&query_date_T=$query_date_T&end_date_D=$end_date_D&end_date_T=$end_date_T$groupQS&SUBMIT=$SUBMIT&group_by=$group_by&search_archived_data=$search_archived_data"; - -$HTML_text.="\n"; -$HTML_text.=""._QXZ("DOWNLOAD")." |"; -$HTML_text.=" "._QXZ("REPORTS")." \n"; -$HTML_text.="\n"; -$HTML_text.="
"; -$HTML_text.="
\n\n"; - -$HTML_text.="
";
-$i=0;
-$group_string='|';
-$group_ct = count($group);
-$HTML_body="";
-
-while($i < $group_ct)
-	{
-
-	$list_stmt="select list_id from vicidial_lists where campaign_id='$group[$i]'";
-	if ($DB) {$HTML_text.="|$list_stmt|\n";}
-	$list_rslt=mysql_to_mysqli($list_stmt, $link);
-	$list_ary=array();
-	while($list_row=mysqli_fetch_row($list_rslt)) 
-		{
-		array_push($list_ary, $list_row[0]);
-		}
-
-	$dispo_ary=array();
-	$dispo_stmt="SELECT status, status_name from vicidial_campaign_statuses where campaign_id='$group[$i]' UNION SELECT status, status_name from vicidial_statuses order by status, status_name";
-	if ($DB) {$HTML_text.="|$dispo_stmt|\n";}
-	$dispo_rslt=mysql_to_mysqli($dispo_stmt, $link);
-	while($dispo_row=mysqli_fetch_row($dispo_rslt)) 
-		{
-		$dispo_ary["$dispo_row[0]"]=$dispo_row[1];
-		}
-
-	$count_ary=array();
-	$total_ary=array();
-	$status_totals=array();
-	$stmt="select lead_id, $group_by, status from ".$vicidial_list_table." where list_id in ('".implode("','", $list_ary)."') and entry_date>='$query_date' and entry_date<='$end_date'";
-	if ($DB) {$HTML_text.="|$stmt|\n";}
-	$rslt=mysql_to_mysqli($stmt, $link);
-	$grand_total=mysqli_num_rows($rslt);
-	while ($row=mysqli_fetch_row($rslt)) 
-		{
-		$count_ary["$row[1]"]["$row[2]"]++;
-		$total_ary["$row[1]"]++;
-		$status_totals["$row[2]"]++;
-		}
-	ksort($count_ary);
-	arsort($total_ary);
-	arsort($status_totals);
-
-	$HTML_body.=""._QXZ("CAMPAIGN").": $group[$i]
\n"; - $ASCII_text.=""._QXZ("CAMPAIGN").": $group[$i]\n"; - $GRAPH.=""._QXZ("CAMPAIGN").": $group[$i]\n"; - $CSV_text.="\""._QXZ("CAMPAIGN").": $group[$i]\"\n"; - - $rpt_group_title=strtoupper(preg_replace('/_/', " ", $group_by)); - - - -# while(list($key, $val)=each($count_ary)) - foreach($count_ary as $key => $val) - { - arsort($count_ary[$key]); - switch ($sort_by) - { - case "dispo_desc": - krsort($count_ary[$key]); - break; - case "dispo_asc": - ksort($count_ary[$key]); - break; - case "count_asc": - asort($count_ary[$key]); - break; - } - - $HTML_body.=""; - $HTML_body.=""; - $HTML_body.=""; - - $ASCII_text.=""._QXZ("$rpt_group_title")." : ".($key !="" ? $key : "("._QXZ("NONE").")")."\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n"; - $ASCII_text.="| "._QXZ("DISPOSITION",40)." | "._QXZ("CALLS",6)." | "._QXZ("PERCENT", 8)." |\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n"; - - # $CSV_text.="\""._QXZ("$rpt_group_title")." : ".($key !="" ? $key : "(NONE)")."\"\n"; - $CSV_text.="\""._QXZ("VENDOR LEAD CODE")."\",\""._QXZ("DISPOSITION")."\",\""._QXZ("CALLS")."\",\""._QXZ("PERCENT")."\"\n"; - - $j=0; -# while(list($key2, $val2)=each($count_ary[$key])) - foreach($count_ary[$key] as $key2 => $val2) - { - if ($j%2==0) - { - $bgcolor=$SSstd_row1_background; - } - else - { - $bgcolor=$SSstd_row2_background; - } - - $percent=sprintf("%.2f", 100*MathZDC($val2, $total_ary["$key"])); - $HTML_body.=""; - $ASCII_text.="| ".sprintf("%-40s", ($dispo_ary["$key2"] !="" ? $dispo_ary["$key2"] : $key2))." | ".sprintf("%6s", $val2)." | ".sprintf("%7s", $percent)."% |\n"; - $CSV_text.="\"".($key !="" ? $key : "("._QXZ("NONE").")")."\",\"".($dispo_ary["$key2"] !="" ? $dispo_ary["$key2"] : $key2)."\",\"".$val2."\",\"".$percent." %\"\n"; - - $j++; - } - $HTML_body.=""; - $HTML_body.="
"._QXZ("$rpt_group_title")." : ".($key !="" ? $key : "("._QXZ("NONE").")")."
"._QXZ("DISPOSITION",40).""._QXZ("CALLS",6).""._QXZ("PERCENT", 7)."
".($dispo_ary["$key2"] !="" ? $dispo_ary["$key2"] : $key2)."".$val2."".$percent." %
"._QXZ("TOTAL")."".$total_ary["$key"]." 

\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n"; - $ASCII_text.="| "._QXZ("TOTAL",40)." | ".sprintf("%6s", $total_ary["$key"])." | ".sprintf("%8s", " ")." |\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n\n"; - $CSV_text.="\"".($key !="" ? $key : "("._QXZ("NONE").")")."\",\""._QXZ("TOTAL")."\",\"".$total_ary["$key"]."\",\"\"\n\n"; - } - $i++; - - $HTML_body.=""; - $HTML_body.=""; - $HTML_body.=""; - - $ASCII_text.=""._QXZ("$rpt_group_title")." : "._QXZ("TOTALS")."\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n"; - $ASCII_text.="| "._QXZ("DISPOSITION",40)." | "._QXZ("CALLS",6)." | "._QXZ("PERCENT", 8)." |\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n"; - - # $CSV_text.="\""._QXZ("$rpt_group_title")." : TOTALS\"\n"; - $CSV_text.="\""._QXZ("VENDOR LEAD CODE")."\",\""._QXZ("DISPOSITION")."\",\""._QXZ("CALLS")."\",\""._QXZ("PERCENT")."\"\n"; - - arsort($status_totals); - switch ($sort_by) - { - case "dispo_desc": - krsort($status_totals); - break; - case "dispo_asc": - ksort($status_totals); - break; - case "count_asc": - asort($status_totals); - break; - } -# while(list($key, $val)=each($status_totals)) - foreach($status_totals as $key => $val) - { - if ($j%2==0) - { - $bgcolor=$SSstd_row1_background; - } - else - { - $bgcolor=$SSstd_row2_background; - } - - $percent=sprintf("%.2f", 100*MathZDC($val, $grand_total)); - $HTML_body.=""; - $ASCII_text.="| ".sprintf("%-40s", ($dispo_ary["$key"] !="" ? $dispo_ary["$key"] : $key))." | ".sprintf("%6s", $val)." | ".sprintf("%7s", $percent)."% |\n"; - $CSV_text.="\""._QXZ("TOTALS")."\",\"".($dispo_ary["$key"] !="" ? $dispo_ary["$key"] : $key)."\",\"".$val."\",\"".$percent." %\"\n"; - - $j++; - } - $HTML_body.=""; - $HTML_body.="
"._QXZ("$rpt_group_title")." : "._QXZ("TOTALS")."
"._QXZ("DISPOSITION",40).""._QXZ("CALLS",6).""._QXZ("PERCENT", 7)."
".($dispo_ary["$key"] !="" ? $dispo_ary["$key"] : $key)."".$val."".$percent." %
"._QXZ("GRAND TOTAL")."".$grand_total." 

\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n"; - $ASCII_text.="| "._QXZ("GRAND TOTAL",40)." | ".sprintf("%6s", $grand_total)." | ".sprintf("%8s", " ")." |\n"; - $ASCII_text.="+------------------------------------------+--------+----------+\n\n"; - $CSV_text.="\"\",\""._QXZ("GRAND TOTAL")."\",\"".$grand_total."\",\"\"\n\n"; - - } - -if ($report_display_type=="HTML") - { - $HTML_text.=$HTML_body; - } -else - { - $HTML_text.=$ASCII_text; - } - -$HTML_text.="
"; - -if ($file_download>0) - { - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "AST_campaign_status_$US$FILE_TIME.csv"; - $CSV_text=preg_replace('/\n +,/', ',', $CSV_text); - $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); - $CSV_text=preg_replace('/\" +/', '"', $CSV_text); - - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - // It will be called LIST_101_20090209-121212.txt - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - } -else - { - header("Content-type: text/html; charset=utf-8"); - - echo $HTML_head; - require("admin_header.php"); - echo $HTML_text; - flush(); - } - -if ($db_source == 'S') - { - mysqli_close($link); - $use_slave_server=0; - $db_source = 'M'; - require("dbconnect_mysqli.php"); - } - -$endMS = microtime(); -$startMSary = explode(" ",$startMS); -$endMSary = explode(" ",$endMS); -$runS = ($endMSary[0] - $startMSary[0]); -$runM = ($endMSary[1] - $startMSary[1]); -$TOTALrun = ($runS + $runM); - -$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); - -exit; - -?> + LICENSE: AGPLv2 +# +# CHANGES +# +# 180211-1111 - First build +# 180214-2230 - Added column to download for VLC or source_id +# 180507-2315 - Added new help display +# 191013-0834 - Fixes for PHP7 +# + +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} + elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} +if (isset($_GET["end_date_D"])) {$end_date_D=$_GET["end_date_D"];} + elseif (isset($_POST["end_date_D"])) {$end_date_D=$_POST["end_date_D"];} +if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} + elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} +if (isset($_GET["end_date_T"])) {$end_date_T=$_GET["end_date_T"];} + elseif (isset($_POST["end_date_T"])) {$end_date_T=$_POST["end_date_T"];} +if (isset($_GET["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} + elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} +if (isset($_GET["group_by"])) {$group_by=$_GET["group_by"];} + elseif (isset($_POST["group_by"])) {$group_by=$_POST["group_by"];} +if (isset($_GET["sort_by"])) {$sort_by=$_GET["sort_by"];} + elseif (isset($_POST["sort_by"])) {$sort_by=$_POST["sort_by"];} +if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} + elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} +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"];} + +$report_name="Outbound Lead Source Report"; +$NOW_DATE = date("Y-m-d"); +if (!isset($group)) {$group=array();} +if (!isset($query_date_D)) {$query_date_D=$NOW_DATE;} +if (!isset($end_date_D)) {$end_date_D=$NOW_DATE;} +if (!isset($query_date_T)) {$query_date_T="00:00:00";} +if (!isset($end_date_T)) {$end_date_T="23:59:59";} + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $SSenable_languages = $row[4]; + $SSlanguage_method = $row[5]; + $SSreport_default_format = $row[6]; + } +##### END SETTINGS LOOKUP ##### +########################################### +if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} + +### ARCHIVED DATA CHECK CONFIGURATION +$archives_available="N"; +$log_tables_array=array("vicidial_list"); +for ($t=0; $t 0) + { + $row=mysqli_fetch_row($rslt); + $VUselected_language = $row[0]; + } + +$auth=0; +$reports_auth=0; +$admin_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $admin_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + if ($reports_auth < 1) + { + $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( ($reports_auth > 0) and ($admin_auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +##### BEGIN log visit to the vicidial_report_log table ##### +$LOGip = getenv("REMOTE_ADDR"); +$LOGbrowser = getenv("HTTP_USER_AGENT"); +$LOGscript_name = getenv("SCRIPT_NAME"); +$LOGserver_name = getenv("SERVER_NAME"); +$LOGserver_port = getenv("SERVER_PORT"); +$LOGrequest_uri = getenv("REQUEST_URI"); +$LOGhttp_referer = getenv("HTTP_REFERER"); +$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); +$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); +$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); +if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} +else {$LOGserver_port = ":$LOGserver_port";} +$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; + +$LOGhostname = php_uname('n'); +if (strlen($LOGhostname)<1) {$LOGhostname='X';} +if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} + +$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$webserver_id_ct = mysqli_num_rows($rslt); +if ($webserver_id_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $webserver_id = $row[0]; + } +else + { + ##### insert webserver entry + $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $affected_rows = mysqli_affected_rows($link); + $webserver_id = mysqli_insert_id($link); + } + +$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$report_log_id = mysqli_insert_id($link); +##### END log visit to the vicidial_report_log table ##### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysqli_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect_mysqli.php"); + $HTML_text.="\n"; + } + +$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {$HTML_text.="|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGuser_group = $row[0]; + +$stmt="SELECT allowed_campaigns,allowed_reports from vicidial_user_groups where user_group='$LOGuser_group';"; +if ($DB) {$HTML_text.="|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGallowed_campaigns = $row[0]; +$LOGallowed_reports = $row[1]; + +if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) + { + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; + exit; + } + +$LOGallowed_campaignsSQL=''; +$whereLOGallowed_campaignsSQL=''; +if ( (!preg_match("/-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')"; + } +$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + $group_string .= "$group[$i]|"; + $i++; + } + +$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$campaigns_to_print = mysqli_num_rows($rslt); +$i=0; +$groups=array(); +while ($i < $campaigns_to_print) + { + $row=mysqli_fetch_row($rslt); + $groups[$i] =$row[0]; + if (preg_match("/-ALL/",$group_string) ) + {$group[$i] = $groups[$i];} + $i++; + } + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) + { + $group_string .= "$group[$i]|"; + $group_SQL .= "'$group[$i]',"; + $groupQS .= "&group[]=$group[$i]"; + } + $i++; + } + +if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) + {$group_SQL = "";} +else + { + $group_SQL = preg_replace("/,\$/",'',$group_SQL); + $group_SQL_str=$group_SQL; + $group_SQL = "and campaign_id IN($group_SQL)"; + } + +$query_date="$query_date_D $query_date_T"; +$end_date="$end_date_D $end_date_T"; + +require("screen_colors.php"); + +# $NWB = "   \"HELP\""; + +$NWB = "\"HELP\""; + +$HTML_head.="\n"; +$HTML_head.="\n"; +$HTML_head.="\n"; + +$HTML_head.="\n"; +$HTML_head.="\n"; +$HTML_head.=""; + +$HTML_head.="\n"; +$HTML_head.="\n"; +$HTML_head.="\n"; +require("chart_button.php"); +$HTML_head.="\n"; +$HTML_head.="\n"; + +$HTML_head.="\n"; +$HTML_head.=""._QXZ("$report_name")."$group_S\n"; +$short_header=1; + +# require("admin_header.php"); + +$HTML_text.="\n"; } - echo "\n"; + echo "\n"; echo "\n"; @@ -27021,11 +27037,12 @@ if ($ADD==31) { ### call function to calculate dialable leads $single_status=1; + $only_return=0; $dial_statuses=" $dispo -"; if ($statuses_complete_list[$dispo] == 'Y') {$Xdialable_count=0;} else - {$Xdialable_count = dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL);} + {$Xdialable_count = dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL,$only_return);} $dialable_total = ($dialable_total + $Xdialable_count); ### get number of complete calls of this status for penetration calculations @@ -27080,8 +27097,9 @@ if ($ADD==31) { ### call function to calculate and print dialable leads $single_status=0; + $only_return=0; $dial_statuses = $dial_statuses_original; - dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL); + dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL,$only_return); echo " - "._QXZ("HIDE")."

"; } else @@ -28671,7 +28689,8 @@ if ($ADD==34) { ### call function to calculate and print dialable leads $single_status=0; - dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL); + $only_return=0; + dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL,$only_return); echo " - "._QXZ("HIDE")."

"; } else @@ -30069,12 +30088,13 @@ if ($ADD==311) { ### call function to calculate dialable leads $single_status=1; + $only_return=0; $dial_statuses=" $dispo -"; $camp_lists=$list_id; if ($statuses_complete_list[$dispo] == 'Y') {$Xdialable_count=0;} else - {$Xdialable_count = dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL);} + {$Xdialable_count = dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL,$only_return);} $dialable_total = ($dialable_total + $Xdialable_count); ### get number of complete calls of this status for penetration calculations @@ -47924,961 +47944,4 @@ else } } - -##### CALCULATE DIALABLE LEADS ##### -function dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL) -{ -##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### -if (isset($camp_lists)) - { - if (strlen($camp_lists)>1) - { - if (strlen($dial_statuses)>2) - { - $g=0; - $p='13'; - $GMT_gmt[0] = ''; - $GMT_hour[0] = ''; - $GMT_day[0] = ''; - $YMD = date("Y-m-d"); - while ($p > -13) - { - $pzone=3600 * $p; - $pmin=(gmdate("i", time() + $pzone)); - $phour=( (gmdate("G", time() + $pzone)) * 100); - $pday=gmdate("w", time() + $pzone); - $tz = sprintf("%.2f", $p); - $GMT_gmt[$g] = "$tz"; - $GMT_day[$g] = "$pday"; - $GMT_hour[$g] = ($phour + $pmin); - $p = ($p - 0.25); - $g++; - } - - $stmt="SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times FROM vicidial_call_times where call_time_id='$local_call_time';"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rowx=mysqli_fetch_row($rslt); - $Gct_default_start = $rowx[3]; - $Gct_default_stop = $rowx[4]; - $Gct_sunday_start = $rowx[5]; - $Gct_sunday_stop = $rowx[6]; - $Gct_monday_start = $rowx[7]; - $Gct_monday_stop = $rowx[8]; - $Gct_tuesday_start = $rowx[9]; - $Gct_tuesday_stop = $rowx[10]; - $Gct_wednesday_start = $rowx[11]; - $Gct_wednesday_stop = $rowx[12]; - $Gct_thursday_start = $rowx[13]; - $Gct_thursday_stop = $rowx[14]; - $Gct_friday_start = $rowx[15]; - $Gct_friday_stop = $rowx[16]; - $Gct_saturday_start = $rowx[17]; - $Gct_saturday_stop = $rowx[18]; - $Gct_state_call_times = $rowx[19]; - $Gct_holidays = $rowx[20]; - - ### BEGIN Check for outbound holiday ### - $holiday_id = ''; - if (strlen($Gct_holidays)>2) - { - $Gct_holidaysSQL = preg_replace("/\|/", "','", "$Gct_holidays"); - $Gct_holidaysSQL = "'".$Gct_holidaysSQL."'"; - - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Gct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $rslt=mysql_to_mysqli($stmt, $link); - if ($DB) {echo "$stmt\n";} - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $holiday_id = $aryC[0]; - $holiday_date = $aryC[1]; - $holiday_name = $aryC[2]; - if($Gct_default_start < $aryC[3]) {$Gct_default_start = $aryC[3];} - if($Gct_default_stop > $aryC[4]) {$Gct_default_stop = $aryC[4];} - if($Gct_sunday_start < $aryC[3]) {$Gct_sunday_start = $aryC[3];} - if($Gct_sunday_stop > $aryC[4]) {$Gct_sunday_stop = $aryC[4];} - if($Gct_monday_start < $aryC[3]) {$Gct_monday_start = $aryC[3];} - if($Gct_monday_stop > $aryC[4]) {$Gct_monday_stop = $aryC[4];} - if($Gct_tuesday_start < $aryC[3]) {$Gct_tuesday_start = $aryC[3];} - if($Gct_tuesday_stop > $aryC[4]) {$Gct_tuesday_stop = $aryC[4];} - if($Gct_wednesday_start < $aryC[3]) {$Gct_wednesday_start = $aryC[3];} - if($Gct_wednesday_stop > $aryC[4]) {$Gct_wednesday_stop = $aryC[4];} - if($Gct_thursday_start < $aryC[3]) {$Gct_thursday_start = $aryC[3];} - if($Gct_thursday_stop > $aryC[4]) {$Gct_thursday_stop = $aryC[4];} - if($Gct_friday_start < $aryC[3]) {$Gct_friday_start = $aryC[3];} - if($Gct_friday_stop > $aryC[4]) {$Gct_friday_stop = $aryC[4];} - if($Gct_saturday_start < $aryC[3]) {$Gct_saturday_start = $aryC[3];} - if($Gct_saturday_stop > $aryC[4]) {$Gct_saturday_stop = $aryC[4];} - if ($DB) {echo "CALL TIME HOLIDAY FOUND! $local_call_time|$holiday_id|$holiday_date|$holiday_name|$Gct_default_start|$Gct_default_stop|\n";} - } - } - ### END Check for outbound holiday ### - - $ct_states = ''; - $ct_state_gmt_SQL = ''; - $ct_srs=0; - $b=0; - if (strlen($Gct_state_call_times)>2) - { - $state_rules = explode('|',$Gct_state_call_times); - $ct_srs = ((count($state_rules)) - 2); - } - while($ct_srs >= $b) - { - if (strlen($state_rules[$b])>1) - { - $stmt="SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $Gstate_call_time_id = $row[0]; - $Gstate_call_time_state = $row[1]; - $Gsct_default_start = $row[4]; - $Gsct_default_stop = $row[5]; - $Gsct_sunday_start = $row[6]; - $Gsct_sunday_stop = $row[7]; - $Gsct_monday_start = $row[8]; - $Gsct_monday_stop = $row[9]; - $Gsct_tuesday_start = $row[10]; - $Gsct_tuesday_stop = $row[11]; - $Gsct_wednesday_start = $row[12]; - $Gsct_wednesday_stop = $row[13]; - $Gsct_thursday_start = $row[14]; - $Gsct_thursday_stop = $row[15]; - $Gsct_friday_start = $row[16]; - $Gsct_friday_stop = $row[17]; - $Gsct_saturday_start = $row[18]; - $Gsct_saturday_stop = $row[19]; - $Sct_holidays = $row[20]; - $ct_states .="'$Gstate_call_time_state',"; - - ### BEGIN Check for outbound state holiday ### - $Sholiday_id = ''; - if ((strlen($Sct_holidays)>2) or ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2))) - { - # Apply state holiday - if (strlen($Sct_holidays)>2) - { - $Sct_holidaysSQL = preg_replace("/\|/", "','", "$Sct_holidays"); - $Sct_holidaysSQL = "'".$Sct_holidaysSQL."'"; - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Sct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "STATE CALL TIME HOLIDAY FOUND! "; - } - # Apply call time wide holiday - elseif ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2)) - { - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id='$holiday_id' and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "NO STATE HOLIDAY APPLYING CALL TIME HOLIDAY! "; - } - $rslt=mysql_to_mysqli($stmt, $link); - if ($DB) {echo "$stmt\n";} - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $Sholiday_id = $aryC[0]; - $Sholiday_date = $aryC[1]; - $Sholiday_name = $aryC[2]; - if ( ($Gsct_default_start < $aryC[3]) && ($Gsct_default_stop > 0) ) {$Gsct_default_start = $aryC[3];} - if ( ($Gsct_default_stop > $aryC[4]) && ($Gsct_default_stop > 0) ) {$Gsct_default_stop = $aryC[4];} - if ( ($Gsct_sunday_start < $aryC[3]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_start = $aryC[3];} - if ( ($Gsct_sunday_stop > $aryC[4]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_stop = $aryC[4];} - if ( ($Gsct_monday_start < $aryC[3]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_start = $aryC[3];} - if ( ($Gsct_monday_stop > $aryC[4]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_stop = $aryC[4];} - if ( ($Gsct_tuesday_start < $aryC[3]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_start = $aryC[3];} - if ( ($Gsct_tuesday_stop > $aryC[4]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_stop = $aryC[4];} - if ( ($Gsct_wednesday_start < $aryC[3]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_start = $aryC[3];} - if ( ($Gsct_wednesday_stop > $aryC[4]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_stop = $aryC[4];} - if ( ($Gsct_thursday_start < $aryC[3]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_start = $aryC[3];} - if ( ($Gsct_thursday_stop > $aryC[4]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_stop = $aryC[4];} - if ( ($Gsct_friday_start < $aryC[3]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_start = $aryC[3];} - if ( ($Gsct_friday_stop > $aryC[4]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_stop = $aryC[4];} - if ( ($Gsct_saturday_start < $aryC[3]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_start = $aryC[3];} - if ( ($Gsct_saturday_stop > $aryC[4]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_stop = $aryC[4];} - if ($DB) {echo "$holidaytype |$Gstate_call_time_id|$Gstate_call_time_state|$Sholiday_id|$Sholiday_date|$Sholiday_name|$Gsct_default_start|$Gsct_default_stop|\n";} - } - } - $r=0; - $state_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gsct_sunday_start==0) and ($Gsct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gsct_monday_start==0) and ($Gsct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gsct_tuesday_start==0) and ($Gsct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gsct_wednesday_start==0) and ($Gsct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gsct_thursday_start==0) and ($Gsct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gsct_friday_start==0) and ($Gsct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gsct_saturday_start==0) and ($Gsct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - $state_gmt = "$state_gmt'99'"; - $ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; - } - - $b++; - } - if (strlen($ct_states)>2) - { - $ct_states = preg_replace('/,$/i', '',$ct_states); - $ct_statesSQL = "and state NOT IN($ct_states)"; - } - else - { - $ct_statesSQL = ""; - } - - $r=0; - $default_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gct_sunday_start==0) and ($Gct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gct_monday_start==0) and ($Gct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gct_tuesday_start==0) and ($Gct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gct_wednesday_start==0) and ($Gct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gct_thursday_start==0) and ($Gct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gct_friday_start==0) and ($Gct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gct_saturday_start==0) and ($Gct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - - $default_gmt = "$default_gmt'99'"; - $all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL"; - - $dial_statuses = preg_replace("/ -$/","",$dial_statuses); - $Dstatuses = explode(" ", $dial_statuses); - $Ds_to_print = (count($Dstatuses) - 0); - $Dsql = ''; - $o=0; - while ($Ds_to_print > $o) - { - $o++; - $Dsql .= "'$Dstatuses[$o]',"; - } - $Dsql = preg_replace("/,$/","",$Dsql); - if (strlen($Dsql) < 2) {$Dsql = "''";} - - $DLTsql=''; - if ($drop_lockout_time > 0) - { - $DLseconds = ($drop_lockout_time * 3600); - $DLseconds = floor($DLseconds); - $DLseconds = intval("$DLseconds"); - $DLTsql = "and ( ( (status IN('DROP','XDROP')) and (last_local_call_time < CONCAT(DATE_ADD(NOW(), INTERVAL -$DLseconds SECOND),' ',CURTIME()) ) ) or (status NOT IN('DROP','XDROP')) )"; - } - - $CCLsql=''; - if ($call_count_limit > 0) - { - $CCLsql = "and (called_count < $call_count_limit)"; - } - - $EXPsql=''; - $expired_lists=''; - $REPORTdate = date("Y-m-d"); - $stmt="SELECT list_id FROM vicidial_lists where list_id IN($camp_lists) and (active='Y') and (expiration_date < \"$REPORTdate\");"; - #$DB=1; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rslt_rows = mysqli_num_rows($rslt); - $f=0; - while ($rslt_rows > $f) - { - $rowx=mysqli_fetch_row($rslt); - $expired_lists .= "'$rowx[0]',"; - $f++; - } - $expired_lists = preg_replace("/,$/",'',$expired_lists); - if (strlen($expired_lists) < 2) {$expired_lists = "''";} - $EXPsql = "and list_id NOT IN($expired_lists)"; - - - ################################# - # Camp List - $stmt="SELECT list_id FROM vicidial_lists where list_id IN($camp_lists) and active='Y';"; - $rslt_list=mysql_to_mysqli($stmt, $link); - $camplists_ct = mysqli_num_rows($rslt_list); - if ($DB) {echo "$camplists_ct|$stmt\n";} - $k=0; - $camp_lists=''; - while ($camplists_ct > $k) - { - $rowA = mysqli_fetch_row($rslt_list); - $camp_lists .= "'$rowA[0]',"; - - ##### Get Call List call time settings - ##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### - $g=0; - $p='13'; - $GMT_gmt[0] = ''; - $GMT_hour[0] = ''; - $GMT_day[0] = ''; - $YMD = date("Y-m-d"); - while ($p > -13) - { - $pzone=3600 * $p; - $pmin=(gmdate("i", time() + $pzone)); - $phour=( (gmdate("G", time() + $pzone)) * 100); - $pday=gmdate("w", time() + $pzone); - $tz = sprintf("%.2f", $p); - $GMT_gmt[$g] = "$tz"; - $GMT_day[$g] = "$pday"; - $GMT_hour[$g] = ($phour + $pmin); - $p = ($p - 0.25); - $g++; - } - - # Set List ID Variable - $cur_list_id = $rowA[0]; - $list_local_call_time = ""; - - # Pull the call times for the lists - $stmt="SELECT local_call_time FROM vicidial_lists where list_id='$cur_list_id';"; - $rslt=mysql_to_mysqli($stmt, $link); - $rslt_ct = mysqli_num_rows($rslt); - if ($rslt_ct > 0) - { - #set Cur call_time - $row=mysqli_fetch_row($rslt); - $cur_call_time = $row[0]; - } - - # check that call time exists - if ($cur_call_time != "campaign") - { - $stmt="SELECT count(*) from vicidial_call_times where call_time_id='$cur_call_time';"; - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $call_time_exists = $row[0]; - if ($call_time_exists < 1) - {$cur_call_time = 'campaign';} - } - - ##### BEGIN local call time for list set different than campaign ##### - if ($cur_call_time != "campaign") - { - ##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### - $stmt = "SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times,ct_holidays FROM vicidial_call_times where call_time_id='$cur_call_time';"; - if ($DB) {echo "$stmt\n";} - $rsltD=mysql_to_mysqli($stmt, $link); - $aryD=mysqli_fetch_row($rsltD); - $Gct_default_start = $aryD[3]; - $Gct_default_stop = $aryD[4]; - $Gct_sunday_start = $aryD[5]; - $Gct_sunday_stop = $aryD[6]; - $Gct_monday_start = $aryD[7]; - $Gct_monday_stop = $aryD[8]; - $Gct_tuesday_start = $aryD[9]; - $Gct_tuesday_stop = $aryD[10]; - $Gct_wednesday_start = $aryD[11]; - $Gct_wednesday_stop = $aryD[12]; - $Gct_thursday_start = $aryD[13]; - $Gct_thursday_stop = $aryD[14]; - $Gct_friday_start = $aryD[15]; - $Gct_friday_stop = $aryD[16]; - $Gct_saturday_start = $aryD[17]; - $Gct_saturday_stop = $aryD[18]; - $Gct_state_call_times = $aryD[19]; - $Gct_holidays = $aryD[20]; - - ### BEGIN Check for outbound holiday ### - $holiday_id = ''; - if (strlen($Gct_holidays)>2) - { - $Gct_holidaysSQL = preg_replace("/\|/", "','", "$Gct_holidays"); - $Gct_holidaysSQL = "'".$Gct_holidaysSQL."'"; - - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Gct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $rslt=mysql_to_mysqli($stmt, $link); - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $holiday_id = $aryC[0]; - $holiday_date = $aryC[1]; - $holiday_name = $aryC[2]; - if ( ($Gct_default_start < $aryC[3]) && ($Gct_default_stop > 0) ) {$Gct_default_start = $aryC[3];} - if ( ($Gct_default_stop > $aryC[4]) && ($Gct_default_stop > 0) ) {$Gct_default_stop = $aryC[4];} - if ( ($Gct_sunday_start < $aryC[3]) && ($Gct_sunday_stop > 0) ) {$Gct_sunday_start = $aryC[3];} - if ( ($Gct_sunday_stop > $aryC[4]) && ($Gct_sunday_stop > 0) ) {$Gct_sunday_stop = $aryC[4];} - if ( ($Gct_monday_start < $aryC[3]) && ($Gct_monday_stop > 0) ) {$Gct_monday_start = $aryC[3];} - if ( ($Gct_monday_stop > $aryC[4]) && ($Gct_monday_stop > 0) ) {$Gct_monday_stop = $aryC[4];} - if ( ($Gct_tuesday_start < $aryC[3]) && ($Gct_tuesday_stop > 0) ) {$Gct_tuesday_start = $aryC[3];} - if ( ($Gct_tuesday_stop > $aryC[4]) && ($Gct_tuesday_stop > 0) ) {$Gct_tuesday_stop = $aryC[4];} - if ( ($Gct_wednesday_start < $aryC[3]) && ($Gct_wednesday_stop > 0) ) {$Gct_wednesday_start = $aryC[3];} - if ( ($Gct_wednesday_stop > $aryC[4]) && ($Gct_wednesday_stop > 0) ) {$Gct_wednesday_stop = $aryC[4];} - if ( ($Gct_thursday_start < $aryC[3]) && ($Gct_thursday_stop > 0) ) {$Gct_thursday_start = $aryC[3];} - if ( ($Gct_thursday_stop > $aryC[4]) && ($Gct_thursday_stop > 0) ) {$Gct_thursday_stop = $aryC[4];} - if ( ($Gct_friday_start < $aryC[3]) && ($Gct_friday_stop > 0) ) {$Gct_friday_start = $aryC[3];} - if ( ($Gct_friday_stop > $aryC[4]) && ($Gct_friday_stop > 0) ) {$Gct_friday_stop = $aryC[4];} - if ( ($Gct_saturday_start < $aryC[3]) && ($Gct_saturday_stop > 0) ) {$Gct_saturday_start = $aryC[3];} - if ( ($Gct_saturday_stop > $aryC[4]) && ($Gct_saturday_stop > 0) ) {$Gct_saturday_stop = $aryC[4];} - if ($DB) {echo "LIST CALL TIME HOLIDAY FOUND! $local_call_time|$holiday_id|$holiday_date|$holiday_name|$Gct_default_start|$Gct_default_stop|\n";} - } - } - ### END Check for outbound holiday ### - - $ct_states = ''; - $ct_state_gmt_SQL = ''; - $ct_srs=0; - $b=0; - if (strlen($Gct_state_call_times)>2) - { - $state_rules = explode('|',$Gct_state_call_times); - $ct_srs = ((count($state_rules)) - 2); - } - while($ct_srs >= $b) - { - if (strlen($state_rules[$b])>1) - { - $stmt = "SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop,ct_holidays from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; - $rslt=mysql_to_mysqli($stmt, $link); - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $Gstate_call_time_id = $aryC[0]; - $Gstate_call_time_state = $aryC[1]; - $Gsct_default_start = $aryC[4]; - $Gsct_default_stop = $aryC[5]; - $Gsct_sunday_start = $aryC[6]; - $Gsct_sunday_stop = $aryC[7]; - $Gsct_monday_start = $aryC[8]; - $Gsct_monday_stop = $aryC[9]; - $Gsct_tuesday_start = $aryC[10]; - $Gsct_tuesday_stop = $aryC[11]; - $Gsct_wednesday_start = $aryC[12]; - $Gsct_wednesday_stop = $aryC[13]; - $Gsct_thursday_start = $aryC[14]; - $Gsct_thursday_stop = $aryC[15]; - $Gsct_friday_start = $aryC[16]; - $Gsct_friday_stop = $aryC[17]; - $Gsct_saturday_start = $aryC[18]; - $Gsct_saturday_stop = $aryC[19]; - $Sct_holidays = $aryC[20]; - $ct_states .="'$Gstate_call_time_state',"; - } - - ### BEGIN Check for outbound state holiday ### - $Sholiday_id = ''; - if ((strlen($Sct_holidays)>2) or ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2))) - { - #Apply state holiday - if (strlen($Sct_holidays)>2) - { - $Sct_holidaysSQL = preg_replace("/\|/", "','", "$Sct_holidays"); - $Sct_holidaysSQL = "'".$Sct_holidaysSQL."'"; - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Sct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "LIST STATE CALL TIME HOLIDAY FOUND! "; - } - #Apply call time wide holiday - elseif ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2)) - { - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id='$holiday_id' and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "LIST NO STATE HOLIDAY APPLYING CALL TIME HOLIDAY! "; - } - $rslt=mysql_to_mysqli($stmt, $link); - if ($DB) {echo "$stmt\n";} - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $Sholiday_id = $aryC[0]; - $Sholiday_date = $aryC[1]; - $Sholiday_name = $aryC[2]; - if ( ($Gsct_default_start < $aryC[3]) && ($Gsct_default_stop > 0) ) {$Gsct_default_start = $aryC[3];} - if ( ($Gsct_default_stop > $aryC[4]) && ($Gsct_default_stop > 0) ) {$Gsct_default_stop = $aryC[4];} - if ( ($Gsct_sunday_start < $aryC[3]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_start = $aryC[3];} - if ( ($Gsct_sunday_stop > $aryC[4]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_stop = $aryC[4];} - if ( ($Gsct_monday_start < $aryC[3]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_start = $aryC[3];} - if ( ($Gsct_monday_stop > $aryC[4]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_stop = $aryC[4];} - if ( ($Gsct_tuesday_start < $aryC[3]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_start = $aryC[3];} - if ( ($Gsct_tuesday_stop > $aryC[4]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_stop = $aryC[4];} - if ( ($Gsct_wednesday_start < $aryC[3]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_start = $aryC[3];} - if ( ($Gsct_wednesday_stop > $aryC[4]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_stop = $aryC[4];} - if ( ($Gsct_thursday_start < $aryC[3]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_start = $aryC[3];} - if ( ($Gsct_thursday_stop > $aryC[4]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_stop = $aryC[4];} - if ( ($Gsct_friday_start < $aryC[3]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_start = $aryC[3];} - if ( ($Gsct_friday_stop > $aryC[4]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_stop = $aryC[4];} - if ( ($Gsct_saturday_start < $aryC[3]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_start = $aryC[3];} - if ( ($Gsct_saturday_stop > $aryC[4]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_stop = $aryC[4];} - if ($DB) {echo "$holidaytype |$Gstate_call_time_id|$Gstate_call_time_state|$Sholiday_id|$Sholiday_date|$Sholiday_name|$Gsct_default_start|$Gsct_default_stop|\n";} - } - } - ### END Check for outbound state holiday ### - - $r=0; - $state_gmt=''; - $del_state_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gsct_sunday_start==0) && ($Gsct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_sunday_start) && ($GMT_hour[$r]<$Gsct_sunday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gsct_monday_start==0) && ($Gsct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_monday_start) && ($GMT_hour[$r]<$Gsct_monday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gsct_tuesday_start==0) && ($Gsct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) && ($GMT_hour[$r]<$Gsct_tuesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gsct_wednesday_start==0) && ($Gsct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) && ($GMT_hour[$r]<$Gsct_wednesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gsct_thursday_start==0) && ($Gsct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_thursday_start) && ($GMT_hour[$r]<$Gsct_thursday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gsct_friday_start==0) && ($Gsct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_friday_start) && ($GMT_hour[$r]<$Gsct_friday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gsct_saturday_start==0) && ($Gsct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_saturday_start) && ($GMT_hour[$r]<$Gsct_saturday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - $state_gmt = "$state_gmt'99'"; - - $del_list_state_gmt_SQL .= "or (List_id=\"$cur_list_id\" and state='$Gstate_call_time_state' and gmt_offset_now NOT IN($state_gmt)) "; - $list_state_gmt_SQL .= "or (List_id=\"$cur_list_id\" and state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; - } - - $b++; - } - if (strlen($ct_states)>2) - { - $ct_states = preg_replace("/,$/i",'',$ct_states); - $ct_statesSQL = "and state NOT IN($ct_states)"; - } - else - { - $ct_statesSQL = ""; - } - - $r=0; - $dgA=0; - $list_default_gmt=''; - while($r < $g) - { - if ($DB > 0) - {echo "LCT_gmt: $r|$GMT_day[$r]|$GMT_gmt[$r]|$Gct_sunday_start|$Gct_sunday_stop|$GMT_hour[$r]|$Gct_default_start|$Gct_default_stop\n";} - - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gct_sunday_start==0) && ($Gct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_sunday_start) && ($GMT_hour[$r]<$Gct_sunday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gct_monday_start==0) && ($Gct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_monday_start) && ($GMT_hour[$r]<$Gct_monday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gct_tuesday_start==0) && ($Gct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_tuesday_start) && ($GMT_hour[$r]<$Gct_tuesday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gct_wednesday_start==0) && ($Gct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_wednesday_start) && ($GMT_hour[$r]<$Gct_wednesday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gct_thursday_start==0) && ($Gct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_thursday_start) && ($GMT_hour[$r]<$Gct_thursday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gct_friday_start==0) && ($Gct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_friday_start) && ($GMT_hour[$r]<$Gct_friday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gct_saturday_start==0) && ($Gct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_saturday_start) && ($GMT_hour[$r]<$Gct_saturday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - - $list_default_gmt = "$list_default_gmt'99'"; - $LCTlist_id_sql .= " or ((list_id='$cur_list_id' and gmt_offset_now NOT IN($list_default_gmt) $ct_statesSQL) $list_state_gmt_SQL)"; - } - ##### END local call time for list set different than campaign ##### - - else - { - if (strlen($list_id_sql) < 3) - { - $list_id_sql = "(list_id IN('$cur_list_id'"; - } - else - { - $list_id_sql .= ",'$cur_list_id'"; - } - } - - $k++; - } - $camp_lists = preg_replace("/.$/i","",$camp_lists); - if (strlen($camp_lists) < 4) {$camp_lists="''";} - if (strlen($list_id_sql) < 4) {$list_id_sql="list_id=''";} - else {$list_id_sql .= '))';} - if (strlen($LCTlist_id_sql) > 1) {$list_id_sql .= "$LCTlist_id_sql";} - - - $stmt="SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN($Dsql) and list_id IN($camp_lists) and ($list_id_sql) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL $EXPsql"; - #$DB=1; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rslt_rows = mysqli_num_rows($rslt); - if ($rslt_rows) - { - $rowx=mysqli_fetch_row($rslt); - $active_leads = "$rowx[0]"; - } - else {$active_leads = '0';} - - if ($DB > 0) {echo "|$DB|\n";} - if ($single_status > 0) - {return $active_leads;} - else - {echo _QXZ("This campaign has")." $active_leads "._QXZ("leads to be dialed in those lists")."\n";} - } - else - { - echo _QXZ("no dial statuses selected for this campaign")."\n"; - } - } - else - { - echo _QXZ("no active lists selected for this campaign")."\n"; - } - } -else - { - echo _QXZ("no active lists selected for this campaign")."\n"; - } -##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ### -} ?> diff --git a/agc_2-X/trunk/www/vicidial/admin_mobile.php b/agc_2-X/trunk/www/vicidial/admin_mobile.php index ba84a332..00ee287c 100644 --- a/agc_2-X/trunk/www/vicidial/admin_mobile.php +++ b/agc_2-X/trunk/www/vicidial/admin_mobile.php @@ -1585,961 +1585,4 @@ else } } - -##### CALCULATE DIALABLE LEADS ##### -function dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL) -{ -##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### -if (isset($camp_lists)) - { - if (strlen($camp_lists)>1) - { - if (strlen($dial_statuses)>2) - { - $g=0; - $p='13'; - $GMT_gmt[0] = ''; - $GMT_hour[0] = ''; - $GMT_day[0] = ''; - $YMD = date("Y-m-d"); - while ($p > -13) - { - $pzone=3600 * $p; - $pmin=(gmdate("i", time() + $pzone)); - $phour=( (gmdate("G", time() + $pzone)) * 100); - $pday=gmdate("w", time() + $pzone); - $tz = sprintf("%.2f", $p); - $GMT_gmt[$g] = "$tz"; - $GMT_day[$g] = "$pday"; - $GMT_hour[$g] = ($phour + $pmin); - $p = ($p - 0.25); - $g++; - } - - $stmt="SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times FROM vicidial_call_times where call_time_id='$local_call_time';"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rowx=mysqli_fetch_row($rslt); - $Gct_default_start = $rowx[3]; - $Gct_default_stop = $rowx[4]; - $Gct_sunday_start = $rowx[5]; - $Gct_sunday_stop = $rowx[6]; - $Gct_monday_start = $rowx[7]; - $Gct_monday_stop = $rowx[8]; - $Gct_tuesday_start = $rowx[9]; - $Gct_tuesday_stop = $rowx[10]; - $Gct_wednesday_start = $rowx[11]; - $Gct_wednesday_stop = $rowx[12]; - $Gct_thursday_start = $rowx[13]; - $Gct_thursday_stop = $rowx[14]; - $Gct_friday_start = $rowx[15]; - $Gct_friday_stop = $rowx[16]; - $Gct_saturday_start = $rowx[17]; - $Gct_saturday_stop = $rowx[18]; - $Gct_state_call_times = $rowx[19]; - $Gct_holidays = $rowx[20]; - - ### BEGIN Check for outbound holiday ### - $holiday_id = ''; - if (strlen($Gct_holidays)>2) - { - $Gct_holidaysSQL = preg_replace("/\|/", "','", "$Gct_holidays"); - $Gct_holidaysSQL = "'".$Gct_holidaysSQL."'"; - - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Gct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $rslt=mysql_to_mysqli($stmt, $link); - if ($DB) {echo "$stmt\n";} - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $holiday_id = $aryC[0]; - $holiday_date = $aryC[1]; - $holiday_name = $aryC[2]; - if($Gct_default_start < $aryC[3]) {$Gct_default_start = $aryC[3];} - if($Gct_default_stop > $aryC[4]) {$Gct_default_stop = $aryC[4];} - if($Gct_sunday_start < $aryC[3]) {$Gct_sunday_start = $aryC[3];} - if($Gct_sunday_stop > $aryC[4]) {$Gct_sunday_stop = $aryC[4];} - if($Gct_monday_start < $aryC[3]) {$Gct_monday_start = $aryC[3];} - if($Gct_monday_stop > $aryC[4]) {$Gct_monday_stop = $aryC[4];} - if($Gct_tuesday_start < $aryC[3]) {$Gct_tuesday_start = $aryC[3];} - if($Gct_tuesday_stop > $aryC[4]) {$Gct_tuesday_stop = $aryC[4];} - if($Gct_wednesday_start < $aryC[3]) {$Gct_wednesday_start = $aryC[3];} - if($Gct_wednesday_stop > $aryC[4]) {$Gct_wednesday_stop = $aryC[4];} - if($Gct_thursday_start < $aryC[3]) {$Gct_thursday_start = $aryC[3];} - if($Gct_thursday_stop > $aryC[4]) {$Gct_thursday_stop = $aryC[4];} - if($Gct_friday_start < $aryC[3]) {$Gct_friday_start = $aryC[3];} - if($Gct_friday_stop > $aryC[4]) {$Gct_friday_stop = $aryC[4];} - if($Gct_saturday_start < $aryC[3]) {$Gct_saturday_start = $aryC[3];} - if($Gct_saturday_stop > $aryC[4]) {$Gct_saturday_stop = $aryC[4];} - if ($DB) {echo "CALL TIME HOLIDAY FOUND! $local_call_time|$holiday_id|$holiday_date|$holiday_name|$Gct_default_start|$Gct_default_stop|\n";} - } - } - ### END Check for outbound holiday ### - - $ct_states = ''; - $ct_state_gmt_SQL = ''; - $ct_srs=0; - $b=0; - if (strlen($Gct_state_call_times)>2) - { - $state_rules = explode('|',$Gct_state_call_times); - $ct_srs = ((count($state_rules)) - 2); - } - while($ct_srs >= $b) - { - if (strlen($state_rules[$b])>1) - { - $stmt="SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $Gstate_call_time_id = $row[0]; - $Gstate_call_time_state = $row[1]; - $Gsct_default_start = $row[4]; - $Gsct_default_stop = $row[5]; - $Gsct_sunday_start = $row[6]; - $Gsct_sunday_stop = $row[7]; - $Gsct_monday_start = $row[8]; - $Gsct_monday_stop = $row[9]; - $Gsct_tuesday_start = $row[10]; - $Gsct_tuesday_stop = $row[11]; - $Gsct_wednesday_start = $row[12]; - $Gsct_wednesday_stop = $row[13]; - $Gsct_thursday_start = $row[14]; - $Gsct_thursday_stop = $row[15]; - $Gsct_friday_start = $row[16]; - $Gsct_friday_stop = $row[17]; - $Gsct_saturday_start = $row[18]; - $Gsct_saturday_stop = $row[19]; - $Sct_holidays = $row[20]; - $ct_states .="'$Gstate_call_time_state',"; - - ### BEGIN Check for outbound state holiday ### - $Sholiday_id = ''; - if ((strlen($Sct_holidays)>2) or ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2))) - { - # Apply state holiday - if (strlen($Sct_holidays)>2) - { - $Sct_holidaysSQL = preg_replace("/\|/", "','", "$Sct_holidays"); - $Sct_holidaysSQL = "'".$Sct_holidaysSQL."'"; - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Sct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "STATE CALL TIME HOLIDAY FOUND! "; - } - # Apply call time wide holiday - elseif ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2)) - { - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id='$holiday_id' and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "NO STATE HOLIDAY APPLYING CALL TIME HOLIDAY! "; - } - $rslt=mysql_to_mysqli($stmt, $link); - if ($DB) {echo "$stmt\n";} - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $Sholiday_id = $aryC[0]; - $Sholiday_date = $aryC[1]; - $Sholiday_name = $aryC[2]; - if ( ($Gsct_default_start < $aryC[3]) && ($Gsct_default_stop > 0) ) {$Gsct_default_start = $aryC[3];} - if ( ($Gsct_default_stop > $aryC[4]) && ($Gsct_default_stop > 0) ) {$Gsct_default_stop = $aryC[4];} - if ( ($Gsct_sunday_start < $aryC[3]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_start = $aryC[3];} - if ( ($Gsct_sunday_stop > $aryC[4]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_stop = $aryC[4];} - if ( ($Gsct_monday_start < $aryC[3]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_start = $aryC[3];} - if ( ($Gsct_monday_stop > $aryC[4]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_stop = $aryC[4];} - if ( ($Gsct_tuesday_start < $aryC[3]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_start = $aryC[3];} - if ( ($Gsct_tuesday_stop > $aryC[4]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_stop = $aryC[4];} - if ( ($Gsct_wednesday_start < $aryC[3]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_start = $aryC[3];} - if ( ($Gsct_wednesday_stop > $aryC[4]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_stop = $aryC[4];} - if ( ($Gsct_thursday_start < $aryC[3]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_start = $aryC[3];} - if ( ($Gsct_thursday_stop > $aryC[4]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_stop = $aryC[4];} - if ( ($Gsct_friday_start < $aryC[3]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_start = $aryC[3];} - if ( ($Gsct_friday_stop > $aryC[4]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_stop = $aryC[4];} - if ( ($Gsct_saturday_start < $aryC[3]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_start = $aryC[3];} - if ( ($Gsct_saturday_stop > $aryC[4]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_stop = $aryC[4];} - if ($DB) {echo "$holidaytype |$Gstate_call_time_id|$Gstate_call_time_state|$Sholiday_id|$Sholiday_date|$Sholiday_name|$Gsct_default_start|$Gsct_default_stop|\n";} - } - } - $r=0; - $state_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gsct_sunday_start==0) and ($Gsct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gsct_monday_start==0) and ($Gsct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gsct_tuesday_start==0) and ($Gsct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gsct_wednesday_start==0) and ($Gsct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gsct_thursday_start==0) and ($Gsct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gsct_friday_start==0) and ($Gsct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gsct_saturday_start==0) and ($Gsct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - $state_gmt = "$state_gmt'99'"; - $ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; - } - - $b++; - } - if (strlen($ct_states)>2) - { - $ct_states = preg_replace('/,$/i', '',$ct_states); - $ct_statesSQL = "and state NOT IN($ct_states)"; - } - else - { - $ct_statesSQL = ""; - } - - $r=0; - $default_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gct_sunday_start==0) and ($Gct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gct_monday_start==0) and ($Gct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gct_tuesday_start==0) and ($Gct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gct_wednesday_start==0) and ($Gct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gct_thursday_start==0) and ($Gct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gct_friday_start==0) and ($Gct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gct_saturday_start==0) and ($Gct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - - $default_gmt = "$default_gmt'99'"; - $all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL"; - - $dial_statuses = preg_replace("/ -$/","",$dial_statuses); - $Dstatuses = explode(" ", $dial_statuses); - $Ds_to_print = (count($Dstatuses) - 0); - $Dsql = ''; - $o=0; - while ($Ds_to_print > $o) - { - $o++; - $Dsql .= "'$Dstatuses[$o]',"; - } - $Dsql = preg_replace("/,$/","",$Dsql); - if (strlen($Dsql) < 2) {$Dsql = "''";} - - $DLTsql=''; - if ($drop_lockout_time > 0) - { - $DLseconds = ($drop_lockout_time * 3600); - $DLseconds = floor($DLseconds); - $DLseconds = intval("$DLseconds"); - $DLTsql = "and ( ( (status IN('DROP','XDROP')) and (last_local_call_time < CONCAT(DATE_ADD(NOW(), INTERVAL -$DLseconds SECOND),' ',CURTIME()) ) ) or (status NOT IN('DROP','XDROP')) )"; - } - - $CCLsql=''; - if ($call_count_limit > 0) - { - $CCLsql = "and (called_count < $call_count_limit)"; - } - - $EXPsql=''; - $expired_lists=''; - $REPORTdate = date("Y-m-d"); - $stmt="SELECT list_id FROM vicidial_lists where list_id IN($camp_lists) and (active='Y') and (expiration_date < \"$REPORTdate\");"; - #$DB=1; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rslt_rows = mysqli_num_rows($rslt); - $f=0; - while ($rslt_rows > $f) - { - $rowx=mysqli_fetch_row($rslt); - $expired_lists .= "'$rowx[0]',"; - $f++; - } - $expired_lists = preg_replace("/,$/",'',$expired_lists); - if (strlen($expired_lists) < 2) {$expired_lists = "''";} - $EXPsql = "and list_id NOT IN($expired_lists)"; - - - ################################# - # Camp List - $stmt="SELECT list_id FROM vicidial_lists where list_id IN($camp_lists) and active='Y';"; - $rslt_list=mysql_to_mysqli($stmt, $link); - $camplists_ct = mysqli_num_rows($rslt_list); - if ($DB) {echo "$camplists_ct|$stmt\n";} - $k=0; - $camp_lists=''; - while ($camplists_ct > $k) - { - $rowA = mysqli_fetch_row($rslt_list); - $camp_lists .= "'$rowA[0]',"; - - ##### Get Call List call time settings - ##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### - $g=0; - $p='13'; - $GMT_gmt[0] = ''; - $GMT_hour[0] = ''; - $GMT_day[0] = ''; - $YMD = date("Y-m-d"); - while ($p > -13) - { - $pzone=3600 * $p; - $pmin=(gmdate("i", time() + $pzone)); - $phour=( (gmdate("G", time() + $pzone)) * 100); - $pday=gmdate("w", time() + $pzone); - $tz = sprintf("%.2f", $p); - $GMT_gmt[$g] = "$tz"; - $GMT_day[$g] = "$pday"; - $GMT_hour[$g] = ($phour + $pmin); - $p = ($p - 0.25); - $g++; - } - - # Set List ID Variable - $cur_list_id = $rowA[0]; - $list_local_call_time = ""; - - # Pull the call times for the lists - $stmt="SELECT local_call_time FROM vicidial_lists where list_id='$cur_list_id';"; - $rslt=mysql_to_mysqli($stmt, $link); - $rslt_ct = mysqli_num_rows($rslt); - if ($rslt_ct > 0) - { - #set Cur call_time - $row=mysqli_fetch_row($rslt); - $cur_call_time = $row[0]; - } - - # check that call time exists - if ($cur_call_time != "campaign") - { - $stmt="SELECT count(*) from vicidial_call_times where call_time_id='$cur_call_time';"; - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $call_time_exists = $row[0]; - if ($call_time_exists < 1) - {$cur_call_time = 'campaign';} - } - - ##### BEGIN local call time for list set different than campaign ##### - if ($cur_call_time != "campaign") - { - ##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### - $stmt = "SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times,ct_holidays FROM vicidial_call_times where call_time_id='$cur_call_time';"; - if ($DB) {echo "$stmt\n";} - $rsltD=mysql_to_mysqli($stmt, $link); - $aryD=mysqli_fetch_row($rsltD); - $Gct_default_start = $aryD[3]; - $Gct_default_stop = $aryD[4]; - $Gct_sunday_start = $aryD[5]; - $Gct_sunday_stop = $aryD[6]; - $Gct_monday_start = $aryD[7]; - $Gct_monday_stop = $aryD[8]; - $Gct_tuesday_start = $aryD[9]; - $Gct_tuesday_stop = $aryD[10]; - $Gct_wednesday_start = $aryD[11]; - $Gct_wednesday_stop = $aryD[12]; - $Gct_thursday_start = $aryD[13]; - $Gct_thursday_stop = $aryD[14]; - $Gct_friday_start = $aryD[15]; - $Gct_friday_stop = $aryD[16]; - $Gct_saturday_start = $aryD[17]; - $Gct_saturday_stop = $aryD[18]; - $Gct_state_call_times = $aryD[19]; - $Gct_holidays = $aryD[20]; - - ### BEGIN Check for outbound holiday ### - $holiday_id = ''; - if (strlen($Gct_holidays)>2) - { - $Gct_holidaysSQL = preg_replace("/\|/", "','", "$Gct_holidays"); - $Gct_holidaysSQL = "'".$Gct_holidaysSQL."'"; - - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Gct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $rslt=mysql_to_mysqli($stmt, $link); - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $holiday_id = $aryC[0]; - $holiday_date = $aryC[1]; - $holiday_name = $aryC[2]; - if ( ($Gct_default_start < $aryC[3]) && ($Gct_default_stop > 0) ) {$Gct_default_start = $aryC[3];} - if ( ($Gct_default_stop > $aryC[4]) && ($Gct_default_stop > 0) ) {$Gct_default_stop = $aryC[4];} - if ( ($Gct_sunday_start < $aryC[3]) && ($Gct_sunday_stop > 0) ) {$Gct_sunday_start = $aryC[3];} - if ( ($Gct_sunday_stop > $aryC[4]) && ($Gct_sunday_stop > 0) ) {$Gct_sunday_stop = $aryC[4];} - if ( ($Gct_monday_start < $aryC[3]) && ($Gct_monday_stop > 0) ) {$Gct_monday_start = $aryC[3];} - if ( ($Gct_monday_stop > $aryC[4]) && ($Gct_monday_stop > 0) ) {$Gct_monday_stop = $aryC[4];} - if ( ($Gct_tuesday_start < $aryC[3]) && ($Gct_tuesday_stop > 0) ) {$Gct_tuesday_start = $aryC[3];} - if ( ($Gct_tuesday_stop > $aryC[4]) && ($Gct_tuesday_stop > 0) ) {$Gct_tuesday_stop = $aryC[4];} - if ( ($Gct_wednesday_start < $aryC[3]) && ($Gct_wednesday_stop > 0) ) {$Gct_wednesday_start = $aryC[3];} - if ( ($Gct_wednesday_stop > $aryC[4]) && ($Gct_wednesday_stop > 0) ) {$Gct_wednesday_stop = $aryC[4];} - if ( ($Gct_thursday_start < $aryC[3]) && ($Gct_thursday_stop > 0) ) {$Gct_thursday_start = $aryC[3];} - if ( ($Gct_thursday_stop > $aryC[4]) && ($Gct_thursday_stop > 0) ) {$Gct_thursday_stop = $aryC[4];} - if ( ($Gct_friday_start < $aryC[3]) && ($Gct_friday_stop > 0) ) {$Gct_friday_start = $aryC[3];} - if ( ($Gct_friday_stop > $aryC[4]) && ($Gct_friday_stop > 0) ) {$Gct_friday_stop = $aryC[4];} - if ( ($Gct_saturday_start < $aryC[3]) && ($Gct_saturday_stop > 0) ) {$Gct_saturday_start = $aryC[3];} - if ( ($Gct_saturday_stop > $aryC[4]) && ($Gct_saturday_stop > 0) ) {$Gct_saturday_stop = $aryC[4];} - if ($DB) {echo "LIST CALL TIME HOLIDAY FOUND! $local_call_time|$holiday_id|$holiday_date|$holiday_name|$Gct_default_start|$Gct_default_stop|\n";} - } - } - ### END Check for outbound holiday ### - - $ct_states = ''; - $ct_state_gmt_SQL = ''; - $ct_srs=0; - $b=0; - if (strlen($Gct_state_call_times)>2) - { - $state_rules = explode('|',$Gct_state_call_times); - $ct_srs = ((count($state_rules)) - 2); - } - while($ct_srs >= $b) - { - if (strlen($state_rules[$b])>1) - { - $stmt = "SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop,ct_holidays from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; - $rslt=mysql_to_mysqli($stmt, $link); - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $Gstate_call_time_id = $aryC[0]; - $Gstate_call_time_state = $aryC[1]; - $Gsct_default_start = $aryC[4]; - $Gsct_default_stop = $aryC[5]; - $Gsct_sunday_start = $aryC[6]; - $Gsct_sunday_stop = $aryC[7]; - $Gsct_monday_start = $aryC[8]; - $Gsct_monday_stop = $aryC[9]; - $Gsct_tuesday_start = $aryC[10]; - $Gsct_tuesday_stop = $aryC[11]; - $Gsct_wednesday_start = $aryC[12]; - $Gsct_wednesday_stop = $aryC[13]; - $Gsct_thursday_start = $aryC[14]; - $Gsct_thursday_stop = $aryC[15]; - $Gsct_friday_start = $aryC[16]; - $Gsct_friday_stop = $aryC[17]; - $Gsct_saturday_start = $aryC[18]; - $Gsct_saturday_stop = $aryC[19]; - $Sct_holidays = $aryC[20]; - $ct_states .="'$Gstate_call_time_state',"; - } - - ### BEGIN Check for outbound state holiday ### - $Sholiday_id = ''; - if ((strlen($Sct_holidays)>2) or ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2))) - { - #Apply state holiday - if (strlen($Sct_holidays)>2) - { - $Sct_holidaysSQL = preg_replace("/\|/", "','", "$Sct_holidays"); - $Sct_holidaysSQL = "'".$Sct_holidaysSQL."'"; - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Sct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "LIST STATE CALL TIME HOLIDAY FOUND! "; - } - #Apply call time wide holiday - elseif ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2)) - { - $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id='$holiday_id' and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; - $holidaytype = "LIST NO STATE HOLIDAY APPLYING CALL TIME HOLIDAY! "; - } - $rslt=mysql_to_mysqli($stmt, $link); - if ($DB) {echo "$stmt\n";} - $sthCrows=mysqli_num_rows($rslt); - if ($sthCrows > 0) - { - $aryC=mysqli_fetch_row($rslt); - $Sholiday_id = $aryC[0]; - $Sholiday_date = $aryC[1]; - $Sholiday_name = $aryC[2]; - if ( ($Gsct_default_start < $aryC[3]) && ($Gsct_default_stop > 0) ) {$Gsct_default_start = $aryC[3];} - if ( ($Gsct_default_stop > $aryC[4]) && ($Gsct_default_stop > 0) ) {$Gsct_default_stop = $aryC[4];} - if ( ($Gsct_sunday_start < $aryC[3]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_start = $aryC[3];} - if ( ($Gsct_sunday_stop > $aryC[4]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_stop = $aryC[4];} - if ( ($Gsct_monday_start < $aryC[3]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_start = $aryC[3];} - if ( ($Gsct_monday_stop > $aryC[4]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_stop = $aryC[4];} - if ( ($Gsct_tuesday_start < $aryC[3]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_start = $aryC[3];} - if ( ($Gsct_tuesday_stop > $aryC[4]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_stop = $aryC[4];} - if ( ($Gsct_wednesday_start < $aryC[3]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_start = $aryC[3];} - if ( ($Gsct_wednesday_stop > $aryC[4]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_stop = $aryC[4];} - if ( ($Gsct_thursday_start < $aryC[3]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_start = $aryC[3];} - if ( ($Gsct_thursday_stop > $aryC[4]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_stop = $aryC[4];} - if ( ($Gsct_friday_start < $aryC[3]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_start = $aryC[3];} - if ( ($Gsct_friday_stop > $aryC[4]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_stop = $aryC[4];} - if ( ($Gsct_saturday_start < $aryC[3]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_start = $aryC[3];} - if ( ($Gsct_saturday_stop > $aryC[4]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_stop = $aryC[4];} - if ($DB) {echo "$holidaytype |$Gstate_call_time_id|$Gstate_call_time_state|$Sholiday_id|$Sholiday_date|$Sholiday_name|$Gsct_default_start|$Gsct_default_stop|\n";} - } - } - ### END Check for outbound state holiday ### - - $r=0; - $state_gmt=''; - $del_state_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gsct_sunday_start==0) && ($Gsct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_sunday_start) && ($GMT_hour[$r]<$Gsct_sunday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gsct_monday_start==0) && ($Gsct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_monday_start) && ($GMT_hour[$r]<$Gsct_monday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gsct_tuesday_start==0) && ($Gsct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) && ($GMT_hour[$r]<$Gsct_tuesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gsct_wednesday_start==0) && ($Gsct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) && ($GMT_hour[$r]<$Gsct_wednesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gsct_thursday_start==0) && ($Gsct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_thursday_start) && ($GMT_hour[$r]<$Gsct_thursday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gsct_friday_start==0) && ($Gsct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_friday_start) && ($GMT_hour[$r]<$Gsct_friday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gsct_saturday_start==0) && ($Gsct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_saturday_start) && ($GMT_hour[$r]<$Gsct_saturday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - $state_gmt = "$state_gmt'99'"; - - $del_list_state_gmt_SQL .= "or (List_id=\"$cur_list_id\" and state='$Gstate_call_time_state' and gmt_offset_now NOT IN($state_gmt)) "; - $list_state_gmt_SQL .= "or (List_id=\"$cur_list_id\" and state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; - } - - $b++; - } - if (strlen($ct_states)>2) - { - $ct_states = preg_replace("/,$/i",'',$ct_states); - $ct_statesSQL = "and state NOT IN($ct_states)"; - } - else - { - $ct_statesSQL = ""; - } - - $r=0; - $dgA=0; - $list_default_gmt=''; - while($r < $g) - { - if ($DB > 0) - {echo "LCT_gmt: $r|$GMT_day[$r]|$GMT_gmt[$r]|$Gct_sunday_start|$Gct_sunday_stop|$GMT_hour[$r]|$Gct_default_start|$Gct_default_stop\n";} - - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gct_sunday_start==0) && ($Gct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_sunday_start) && ($GMT_hour[$r]<$Gct_sunday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gct_monday_start==0) && ($Gct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_monday_start) && ($GMT_hour[$r]<$Gct_monday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gct_tuesday_start==0) && ($Gct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_tuesday_start) && ($GMT_hour[$r]<$Gct_tuesday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gct_wednesday_start==0) && ($Gct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_wednesday_start) && ($GMT_hour[$r]<$Gct_wednesday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gct_thursday_start==0) && ($Gct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_thursday_start) && ($GMT_hour[$r]<$Gct_thursday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gct_friday_start==0) && ($Gct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_friday_start) && ($GMT_hour[$r]<$Gct_friday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gct_saturday_start==0) && ($Gct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_saturday_start) && ($GMT_hour[$r]<$Gct_saturday_stop) ) - {} - else - {$list_default_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - - $list_default_gmt = "$list_default_gmt'99'"; - $LCTlist_id_sql .= " or ((list_id='$cur_list_id' and gmt_offset_now NOT IN($list_default_gmt) $ct_statesSQL) $list_state_gmt_SQL)"; - } - ##### END local call time for list set different than campaign ##### - - else - { - if (strlen($list_id_sql) < 3) - { - $list_id_sql = "(list_id IN('$cur_list_id'"; - } - else - { - $list_id_sql .= ",'$cur_list_id'"; - } - } - - $k++; - } - $camp_lists = preg_replace("/.$/i","",$camp_lists); - if (strlen($camp_lists) < 4) {$camp_lists="''";} - if (strlen($list_id_sql) < 4) {$list_id_sql="list_id=''";} - else {$list_id_sql .= '))';} - if (strlen($LCTlist_id_sql) > 1) {$list_id_sql .= "$LCTlist_id_sql";} - - - $stmt="SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN($Dsql) and list_id IN($camp_lists) and ($list_id_sql) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL $EXPsql"; - #$DB=1; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rslt_rows = mysqli_num_rows($rslt); - if ($rslt_rows) - { - $rowx=mysqli_fetch_row($rslt); - $active_leads = "$rowx[0]"; - } - else {$active_leads = '0';} - - if ($DB > 0) {echo "|$DB|\n";} - if ($single_status > 0) - {return $active_leads;} - else - {echo _QXZ("This campaign has")." $active_leads "._QXZ("leads to be dialed in those lists")."\n";} - } - else - { - echo _QXZ("no dial statuses selected for this campaign")."\n"; - } - } - else - { - echo _QXZ("no active lists selected for this campaign")."\n"; - } - } -else - { - echo _QXZ("no active lists selected for this campaign")."\n"; - } -##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ### -} ?> diff --git a/agc_2-X/trunk/www/vicidial/count_functions.inc b/agc_2-X/trunk/www/vicidial/count_functions.inc index 82671623..c78ac02d 100644 --- a/agc_2-X/trunk/www/vicidial/count_functions.inc +++ b/agc_2-X/trunk/www/vicidial/count_functions.inc @@ -85,372 +85,4 @@ else } -##### CALCULATE DIALABLE LEADS ##### -function dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL) -{ - -global $full_dialable_SQL; - -##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### -if (isset($camp_lists)) - { - if (strlen($camp_lists)>1) - { - if (strlen($dial_statuses)>2) - { - $g=0; - $p='13'; - $GMT_gmt[0] = ''; - $GMT_hour[0] = ''; - $GMT_day[0] = ''; - while ($p > -13) - { - $pzone=3600 * $p; - $pmin=(gmdate("i", time() + $pzone)); - $phour=( (gmdate("G", time() + $pzone)) * 100); - $pday=gmdate("w", time() + $pzone); - $tz = sprintf("%.2f", $p); - $GMT_gmt[$g] = "$tz"; - $GMT_day[$g] = "$pday"; - $GMT_hour[$g] = ($phour + $pmin); - $p = ($p - 0.25); - $g++; - } - - $stmt="SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times FROM vicidial_call_times where call_time_id='$local_call_time';"; - if ($DB) {$HTML_header.="$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rowx=mysqli_fetch_row($rslt); - $Gct_default_start = $rowx[3]; - $Gct_default_stop = $rowx[4]; - $Gct_sunday_start = $rowx[5]; - $Gct_sunday_stop = $rowx[6]; - $Gct_monday_start = $rowx[7]; - $Gct_monday_stop = $rowx[8]; - $Gct_tuesday_start = $rowx[9]; - $Gct_tuesday_stop = $rowx[10]; - $Gct_wednesday_start = $rowx[11]; - $Gct_wednesday_stop = $rowx[12]; - $Gct_thursday_start = $rowx[13]; - $Gct_thursday_stop = $rowx[14]; - $Gct_friday_start = $rowx[15]; - $Gct_friday_stop = $rowx[16]; - $Gct_saturday_start = $rowx[17]; - $Gct_saturday_stop = $rowx[18]; - $Gct_state_call_times = $rowx[19]; - - $ct_states = ''; - $ct_state_gmt_SQL = ''; - $ct_srs=0; - $b=0; - if (strlen($Gct_state_call_times)>2) - { - $state_rules = explode('|',$Gct_state_call_times); - $ct_srs = ((count($state_rules)) - 2); - } - while($ct_srs >= $b) - { - if (strlen($state_rules[$b])>1) - { - $stmt="SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $Gstate_call_time_id = $row[0]; - $Gstate_call_time_state = $row[1]; - $Gsct_default_start = $row[4]; - $Gsct_default_stop = $row[5]; - $Gsct_sunday_start = $row[6]; - $Gsct_sunday_stop = $row[7]; - $Gsct_monday_start = $row[8]; - $Gsct_monday_stop = $row[9]; - $Gsct_tuesday_start = $row[10]; - $Gsct_tuesday_stop = $row[11]; - $Gsct_wednesday_start = $row[12]; - $Gsct_wednesday_stop = $row[13]; - $Gsct_thursday_start = $row[14]; - $Gsct_thursday_stop = $row[15]; - $Gsct_friday_start = $row[16]; - $Gsct_friday_stop = $row[17]; - $Gsct_saturday_start = $row[18]; - $Gsct_saturday_stop = $row[19]; - - $ct_states .="'$Gstate_call_time_state',"; - - $r=0; - $state_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gsct_sunday_start==0) and ($Gsct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gsct_monday_start==0) and ($Gsct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gsct_tuesday_start==0) and ($Gsct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gsct_wednesday_start==0) and ($Gsct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gsct_thursday_start==0) and ($Gsct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gsct_friday_start==0) and ($Gsct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gsct_saturday_start==0) and ($Gsct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) ) - {$state_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - $state_gmt = "$state_gmt'99'"; - $ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; - } - - $b++; - } - if (strlen($ct_states)>2) - { - $ct_states = eregi_replace(",$",'',$ct_states); - $ct_statesSQL = "and state NOT IN($ct_states)"; - } - else - { - $ct_statesSQL = ""; - } - - $r=0; - $default_gmt=''; - while($r < $g) - { - if ($GMT_day[$r]==0) #### Sunday local time - { - if (($Gct_sunday_start==0) and ($Gct_sunday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==1) #### Monday local time - { - if (($Gct_monday_start==0) and ($Gct_monday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==2) #### Tuesday local time - { - if (($Gct_tuesday_start==0) and ($Gct_tuesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==3) #### Wednesday local time - { - if (($Gct_wednesday_start==0) and ($Gct_wednesday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==4) #### Thursday local time - { - if (($Gct_thursday_start==0) and ($Gct_thursday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==5) #### Friday local time - { - if (($Gct_friday_start==0) and ($Gct_friday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - if ($GMT_day[$r]==6) #### Saturday local time - { - if (($Gct_saturday_start==0) and ($Gct_saturday_stop==0)) - { - if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - else - { - if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) ) - {$default_gmt.="'$GMT_gmt[$r]',";} - } - } - $r++; - } - - $default_gmt = "$default_gmt'99'"; - $all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL"; - - $dial_statuses = preg_replace("/ -$/","",$dial_statuses); - $Dstatuses = explode(" ", $dial_statuses); - $Ds_to_print = (count($Dstatuses) - 0); - $Dsql = ''; - $o=0; - while ($Ds_to_print > $o) - { - $o++; - $Dsql .= "'$Dstatuses[$o]',"; - } - $Dsql = preg_replace("/,$/","",$Dsql); - if (strlen($Dsql) < 2) {$Dsql = "''";} - - $DLTsql=''; - if ($drop_lockout_time > 0) - { - $DLseconds = ($drop_lockout_time * 3600); - $DLseconds = floor($DLseconds); - $DLseconds = intval("$DLseconds"); - $DLTsql = "and ( ( (status IN('DROP','XDROP')) and (last_local_call_time < CONCAT(DATE_ADD(NOW(), INTERVAL -$DLseconds SECOND),' ',CURTIME()) ) ) or (status NOT IN('DROP','XDROP')) )"; - } - - $CCLsql=''; - if ($call_count_limit > 0) - { - $CCLsql = "and (called_count < $call_count_limit)"; - } - - $stmt="SELECT count(*) FROM vicidial_list where status IN($Dsql) and list_id IN($camp_lists) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL"; - $full_dialable_SQL="status IN($Dsql) and list_id IN($camp_lists) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL"; - #$DB=1; - if ($DB) {$HTML_header.="$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $rslt_rows = mysqli_num_rows($rslt); - if ($rslt_rows) - { - $rowx=mysqli_fetch_row($rslt); - $active_leads = "$rowx[0]"; - } - else {$active_leads = '0';} - - if ($DB > 0) {$HTML_header.="|$DB|\n";} - if ($single_status > 0) - {return $active_leads;} - else - {$HTML_header.=_QXZ("This campaign has $active_leads leads to be dialed in those lists")."\n";} - } - else - { - $HTML_header.=_QXZ("no dial statuses selected for this campaign")."\n"; - } - } - else - { - $HTML_header.=_QXZ("no active lists selected for this campaign")."\n"; - } - } -else - { - $HTML_header.=_QXZ("no active lists selected for this campaign")."\n"; - } -##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ### -} ?> diff --git a/agc_2-X/trunk/www/vicidial/functions.php b/agc_2-X/trunk/www/vicidial/functions.php index c4192961..d0ce6224 100644 --- a/agc_2-X/trunk/www/vicidial/functions.php +++ b/agc_2-X/trunk/www/vicidial/functions.php @@ -37,6 +37,7 @@ # 200401-1920 - Added TimeToText function to convert integers to strings # 210311-2316 - Added 2FA check in user_authorization function # 210316-0924 - Small fix for 2FA consistency +# 210406-1740 - Moved 'dialable_leads' function to this script # ##### BEGIN validate user login credentials, check for failed lock out ##### @@ -1544,4 +1545,970 @@ function createDateRangeArray($strDateFrom,$strDateTo) return $aryRange; } + +##### CALCULATE DIALABLE LEADS ##### +function dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL,$only_return) +{ +global $full_dialable_SQL; +$dialable_output=''; +##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### +if (isset($camp_lists)) + { + if (strlen($camp_lists)>1) + { + if (strlen($dial_statuses)>2) + { + $g=0; + $p='13'; + $GMT_gmt[0] = ''; + $GMT_hour[0] = ''; + $GMT_day[0] = ''; + $YMD = date("Y-m-d"); + while ($p > -13) + { + $pzone=3600 * $p; + $pmin=(gmdate("i", time() + $pzone)); + $phour=( (gmdate("G", time() + $pzone)) * 100); + $pday=gmdate("w", time() + $pzone); + $tz = sprintf("%.2f", $p); + $GMT_gmt[$g] = "$tz"; + $GMT_day[$g] = "$pday"; + $GMT_hour[$g] = ($phour + $pmin); + $p = ($p - 0.25); + $g++; + } + + $stmt="SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times FROM vicidial_call_times where call_time_id='$local_call_time';"; + if ($DB) {$dialable_output .= "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $rowx=mysqli_fetch_row($rslt); + $Gct_default_start = $rowx[3]; + $Gct_default_stop = $rowx[4]; + $Gct_sunday_start = $rowx[5]; + $Gct_sunday_stop = $rowx[6]; + $Gct_monday_start = $rowx[7]; + $Gct_monday_stop = $rowx[8]; + $Gct_tuesday_start = $rowx[9]; + $Gct_tuesday_stop = $rowx[10]; + $Gct_wednesday_start = $rowx[11]; + $Gct_wednesday_stop = $rowx[12]; + $Gct_thursday_start = $rowx[13]; + $Gct_thursday_stop = $rowx[14]; + $Gct_friday_start = $rowx[15]; + $Gct_friday_stop = $rowx[16]; + $Gct_saturday_start = $rowx[17]; + $Gct_saturday_stop = $rowx[18]; + $Gct_state_call_times = $rowx[19]; + $Gct_holidays = $rowx[20]; + + ### BEGIN Check for outbound holiday ### + $holiday_id = ''; + if (strlen($Gct_holidays)>2) + { + $Gct_holidaysSQL = preg_replace("/\|/", "','", "$Gct_holidays"); + $Gct_holidaysSQL = "'".$Gct_holidaysSQL."'"; + + $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Gct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {$dialable_output .= "$stmt\n";} + $sthCrows=mysqli_num_rows($rslt); + if ($sthCrows > 0) + { + $aryC=mysqli_fetch_row($rslt); + $holiday_id = $aryC[0]; + $holiday_date = $aryC[1]; + $holiday_name = $aryC[2]; + if($Gct_default_start < $aryC[3]) {$Gct_default_start = $aryC[3];} + if($Gct_default_stop > $aryC[4]) {$Gct_default_stop = $aryC[4];} + if($Gct_sunday_start < $aryC[3]) {$Gct_sunday_start = $aryC[3];} + if($Gct_sunday_stop > $aryC[4]) {$Gct_sunday_stop = $aryC[4];} + if($Gct_monday_start < $aryC[3]) {$Gct_monday_start = $aryC[3];} + if($Gct_monday_stop > $aryC[4]) {$Gct_monday_stop = $aryC[4];} + if($Gct_tuesday_start < $aryC[3]) {$Gct_tuesday_start = $aryC[3];} + if($Gct_tuesday_stop > $aryC[4]) {$Gct_tuesday_stop = $aryC[4];} + if($Gct_wednesday_start < $aryC[3]) {$Gct_wednesday_start = $aryC[3];} + if($Gct_wednesday_stop > $aryC[4]) {$Gct_wednesday_stop = $aryC[4];} + if($Gct_thursday_start < $aryC[3]) {$Gct_thursday_start = $aryC[3];} + if($Gct_thursday_stop > $aryC[4]) {$Gct_thursday_stop = $aryC[4];} + if($Gct_friday_start < $aryC[3]) {$Gct_friday_start = $aryC[3];} + if($Gct_friday_stop > $aryC[4]) {$Gct_friday_stop = $aryC[4];} + if($Gct_saturday_start < $aryC[3]) {$Gct_saturday_start = $aryC[3];} + if($Gct_saturday_stop > $aryC[4]) {$Gct_saturday_stop = $aryC[4];} + if ($DB) {$dialable_output .= "CALL TIME HOLIDAY FOUND! $local_call_time|$holiday_id|$holiday_date|$holiday_name|$Gct_default_start|$Gct_default_stop|\n";} + } + } + ### END Check for outbound holiday ### + + $ct_states = ''; + $ct_state_gmt_SQL = ''; + $ct_srs=0; + $b=0; + if (strlen($Gct_state_call_times)>2) + { + $state_rules = explode('|',$Gct_state_call_times); + $ct_srs = ((count($state_rules)) - 2); + } + while($ct_srs >= $b) + { + if (strlen($state_rules[$b])>1) + { + $stmt="SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $Gstate_call_time_id = $row[0]; + $Gstate_call_time_state = $row[1]; + $Gsct_default_start = $row[4]; + $Gsct_default_stop = $row[5]; + $Gsct_sunday_start = $row[6]; + $Gsct_sunday_stop = $row[7]; + $Gsct_monday_start = $row[8]; + $Gsct_monday_stop = $row[9]; + $Gsct_tuesday_start = $row[10]; + $Gsct_tuesday_stop = $row[11]; + $Gsct_wednesday_start = $row[12]; + $Gsct_wednesday_stop = $row[13]; + $Gsct_thursday_start = $row[14]; + $Gsct_thursday_stop = $row[15]; + $Gsct_friday_start = $row[16]; + $Gsct_friday_stop = $row[17]; + $Gsct_saturday_start = $row[18]; + $Gsct_saturday_stop = $row[19]; + $Sct_holidays = $row[20]; + $ct_states .="'$Gstate_call_time_state',"; + + ### BEGIN Check for outbound state holiday ### + $Sholiday_id = ''; + if ((strlen($Sct_holidays)>2) or ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2))) + { + # Apply state holiday + if (strlen($Sct_holidays)>2) + { + $Sct_holidaysSQL = preg_replace("/\|/", "','", "$Sct_holidays"); + $Sct_holidaysSQL = "'".$Sct_holidaysSQL."'"; + $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Sct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; + $holidaytype = "STATE CALL TIME HOLIDAY FOUND! "; + } + # Apply call time wide holiday + elseif ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2)) + { + $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id='$holiday_id' and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; + $holidaytype = "NO STATE HOLIDAY APPLYING CALL TIME HOLIDAY! "; + } + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {$dialable_output .= "$stmt\n";} + $sthCrows=mysqli_num_rows($rslt); + if ($sthCrows > 0) + { + $aryC=mysqli_fetch_row($rslt); + $Sholiday_id = $aryC[0]; + $Sholiday_date = $aryC[1]; + $Sholiday_name = $aryC[2]; + if ( ($Gsct_default_start < $aryC[3]) && ($Gsct_default_stop > 0) ) {$Gsct_default_start = $aryC[3];} + if ( ($Gsct_default_stop > $aryC[4]) && ($Gsct_default_stop > 0) ) {$Gsct_default_stop = $aryC[4];} + if ( ($Gsct_sunday_start < $aryC[3]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_start = $aryC[3];} + if ( ($Gsct_sunday_stop > $aryC[4]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_stop = $aryC[4];} + if ( ($Gsct_monday_start < $aryC[3]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_start = $aryC[3];} + if ( ($Gsct_monday_stop > $aryC[4]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_stop = $aryC[4];} + if ( ($Gsct_tuesday_start < $aryC[3]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_start = $aryC[3];} + if ( ($Gsct_tuesday_stop > $aryC[4]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_stop = $aryC[4];} + if ( ($Gsct_wednesday_start < $aryC[3]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_start = $aryC[3];} + if ( ($Gsct_wednesday_stop > $aryC[4]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_stop = $aryC[4];} + if ( ($Gsct_thursday_start < $aryC[3]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_start = $aryC[3];} + if ( ($Gsct_thursday_stop > $aryC[4]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_stop = $aryC[4];} + if ( ($Gsct_friday_start < $aryC[3]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_start = $aryC[3];} + if ( ($Gsct_friday_stop > $aryC[4]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_stop = $aryC[4];} + if ( ($Gsct_saturday_start < $aryC[3]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_start = $aryC[3];} + if ( ($Gsct_saturday_stop > $aryC[4]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_stop = $aryC[4];} + if ($DB) {$dialable_output .= "$holidaytype |$Gstate_call_time_id|$Gstate_call_time_state|$Sholiday_id|$Sholiday_date|$Sholiday_name|$Gsct_default_start|$Gsct_default_stop|\n";} + } + } + $r=0; + $state_gmt=''; + while($r < $g) + { + if ($GMT_day[$r]==0) #### Sunday local time + { + if (($Gsct_sunday_start==0) and ($Gsct_sunday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_sunday_start) and ($GMT_hour[$r]<$Gsct_sunday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==1) #### Monday local time + { + if (($Gsct_monday_start==0) and ($Gsct_monday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_monday_start) and ($GMT_hour[$r]<$Gsct_monday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==2) #### Tuesday local time + { + if (($Gsct_tuesday_start==0) and ($Gsct_tuesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) and ($GMT_hour[$r]<$Gsct_tuesday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==3) #### Wednesday local time + { + if (($Gsct_wednesday_start==0) and ($Gsct_wednesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) and ($GMT_hour[$r]<$Gsct_wednesday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==4) #### Thursday local time + { + if (($Gsct_thursday_start==0) and ($Gsct_thursday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_thursday_start) and ($GMT_hour[$r]<$Gsct_thursday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==5) #### Friday local time + { + if (($Gsct_friday_start==0) and ($Gsct_friday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_friday_start) and ($GMT_hour[$r]<$Gsct_friday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==6) #### Saturday local time + { + if (($Gsct_saturday_start==0) and ($Gsct_saturday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) and ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_saturday_start) and ($GMT_hour[$r]<$Gsct_saturday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + $r++; + } + $state_gmt = "$state_gmt'99'"; + $ct_state_gmt_SQL .= "or (state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; + } + + $b++; + } + if (strlen($ct_states)>2) + { + $ct_states = preg_replace('/,$/i', '',$ct_states); + $ct_statesSQL = "and state NOT IN($ct_states)"; + } + else + { + $ct_statesSQL = ""; + } + + $r=0; + $default_gmt=''; + while($r < $g) + { + if ($GMT_day[$r]==0) #### Sunday local time + { + if (($Gct_sunday_start==0) and ($Gct_sunday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_sunday_start) and ($GMT_hour[$r]<$Gct_sunday_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==1) #### Monday local time + { + if (($Gct_monday_start==0) and ($Gct_monday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_monday_start) and ($GMT_hour[$r]<$Gct_monday_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==2) #### Tuesday local time + { + if (($Gct_tuesday_start==0) and ($Gct_tuesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_tuesday_start) and ($GMT_hour[$r]<$Gct_tuesday_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==3) #### Wednesday local time + { + if (($Gct_wednesday_start==0) and ($Gct_wednesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_wednesday_start) and ($GMT_hour[$r]<$Gct_wednesday_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==4) #### Thursday local time + { + if (($Gct_thursday_start==0) and ($Gct_thursday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_thursday_start) and ($GMT_hour[$r]<$Gct_thursday_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==5) #### Friday local time + { + if (($Gct_friday_start==0) and ($Gct_friday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_friday_start) and ($GMT_hour[$r]<$Gct_friday_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==6) #### Saturday local time + { + if (($Gct_saturday_start==0) and ($Gct_saturday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) and ($GMT_hour[$r]<$Gct_default_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_saturday_start) and ($GMT_hour[$r]<$Gct_saturday_stop) ) + {$default_gmt.="'$GMT_gmt[$r]',";} + } + } + $r++; + } + + $default_gmt = "$default_gmt'99'"; + $all_gmtSQL = "(gmt_offset_now IN($default_gmt) $ct_statesSQL) $ct_state_gmt_SQL"; + + $dial_statuses = preg_replace("/ -$/","",$dial_statuses); + $Dstatuses = explode(" ", $dial_statuses); + $Ds_to_print = (count($Dstatuses) - 0); + $Dsql = ''; + $o=0; + while ($Ds_to_print > $o) + { + $o++; + $Dsql .= "'$Dstatuses[$o]',"; + } + $Dsql = preg_replace("/,$/","",$Dsql); + if (strlen($Dsql) < 2) {$Dsql = "''";} + + $DLTsql=''; + if ($drop_lockout_time > 0) + { + $DLseconds = ($drop_lockout_time * 3600); + $DLseconds = floor($DLseconds); + $DLseconds = intval("$DLseconds"); + $DLTsql = "and ( ( (status IN('DROP','XDROP')) and (last_local_call_time < CONCAT(DATE_ADD(NOW(), INTERVAL -$DLseconds SECOND),' ',CURTIME()) ) ) or (status NOT IN('DROP','XDROP')) )"; + } + + $CCLsql=''; + if ($call_count_limit > 0) + { + $CCLsql = "and (called_count < $call_count_limit)"; + } + + $EXPsql=''; + $expired_lists=''; + $REPORTdate = date("Y-m-d"); + $stmt="SELECT list_id FROM vicidial_lists where list_id IN($camp_lists) and (active='Y') and (expiration_date < \"$REPORTdate\");"; + #$DB=1; + if ($DB) {$dialable_output .= "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $rslt_rows = mysqli_num_rows($rslt); + $f=0; + while ($rslt_rows > $f) + { + $rowx=mysqli_fetch_row($rslt); + $expired_lists .= "'$rowx[0]',"; + $f++; + } + $expired_lists = preg_replace("/,$/",'',$expired_lists); + if (strlen($expired_lists) < 2) {$expired_lists = "''";} + $EXPsql = "and list_id NOT IN($expired_lists)"; + + + ################################# + # Camp List + $stmt="SELECT list_id FROM vicidial_lists where list_id IN($camp_lists) and active='Y';"; + $rslt_list=mysql_to_mysqli($stmt, $link); + $camplists_ct = mysqli_num_rows($rslt_list); + if ($DB) {$dialable_output .= "$camplists_ct|$stmt\n";} + $k=0; + $camp_lists=''; + while ($camplists_ct > $k) + { + $rowA = mysqli_fetch_row($rslt_list); + $camp_lists .= "'$rowA[0]',"; + + ##### Get Call List call time settings + ##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### + $g=0; + $p='13'; + $GMT_gmt[0] = ''; + $GMT_hour[0] = ''; + $GMT_day[0] = ''; + $YMD = date("Y-m-d"); + while ($p > -13) + { + $pzone=3600 * $p; + $pmin=(gmdate("i", time() + $pzone)); + $phour=( (gmdate("G", time() + $pzone)) * 100); + $pday=gmdate("w", time() + $pzone); + $tz = sprintf("%.2f", $p); + $GMT_gmt[$g] = "$tz"; + $GMT_day[$g] = "$pday"; + $GMT_hour[$g] = ($phour + $pmin); + $p = ($p - 0.25); + $g++; + } + + # Set List ID Variable + $cur_list_id = $rowA[0]; + $list_local_call_time = ""; + + # Pull the call times for the lists + $stmt="SELECT local_call_time FROM vicidial_lists where list_id='$cur_list_id';"; + $rslt=mysql_to_mysqli($stmt, $link); + $rslt_ct = mysqli_num_rows($rslt); + if ($rslt_ct > 0) + { + #set Cur call_time + $row=mysqli_fetch_row($rslt); + $cur_call_time = $row[0]; + } + + # check that call time exists + if ($cur_call_time != "campaign") + { + $stmt="SELECT count(*) from vicidial_call_times where call_time_id='$cur_call_time';"; + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $call_time_exists = $row[0]; + if ($call_time_exists < 1) + {$cur_call_time = 'campaign';} + } + + ##### BEGIN local call time for list set different than campaign ##### + if ($cur_call_time != "campaign") + { + ##### BEGIN calculate what gmt_offset_now values are within the allowed local_call_time setting ### + $stmt = "SELECT call_time_id,call_time_name,call_time_comments,ct_default_start,ct_default_stop,ct_sunday_start,ct_sunday_stop,ct_monday_start,ct_monday_stop,ct_tuesday_start,ct_tuesday_stop,ct_wednesday_start,ct_wednesday_stop,ct_thursday_start,ct_thursday_stop,ct_friday_start,ct_friday_stop,ct_saturday_start,ct_saturday_stop,ct_state_call_times,ct_holidays FROM vicidial_call_times where call_time_id='$cur_call_time';"; + if ($DB) {$dialable_output .= "$stmt\n";} + $rsltD=mysql_to_mysqli($stmt, $link); + $aryD=mysqli_fetch_row($rsltD); + $Gct_default_start = $aryD[3]; + $Gct_default_stop = $aryD[4]; + $Gct_sunday_start = $aryD[5]; + $Gct_sunday_stop = $aryD[6]; + $Gct_monday_start = $aryD[7]; + $Gct_monday_stop = $aryD[8]; + $Gct_tuesday_start = $aryD[9]; + $Gct_tuesday_stop = $aryD[10]; + $Gct_wednesday_start = $aryD[11]; + $Gct_wednesday_stop = $aryD[12]; + $Gct_thursday_start = $aryD[13]; + $Gct_thursday_stop = $aryD[14]; + $Gct_friday_start = $aryD[15]; + $Gct_friday_stop = $aryD[16]; + $Gct_saturday_start = $aryD[17]; + $Gct_saturday_stop = $aryD[18]; + $Gct_state_call_times = $aryD[19]; + $Gct_holidays = $aryD[20]; + + ### BEGIN Check for outbound holiday ### + $holiday_id = ''; + if (strlen($Gct_holidays)>2) + { + $Gct_holidaysSQL = preg_replace("/\|/", "','", "$Gct_holidays"); + $Gct_holidaysSQL = "'".$Gct_holidaysSQL."'"; + + $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Gct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; + $rslt=mysql_to_mysqli($stmt, $link); + $sthCrows=mysqli_num_rows($rslt); + if ($sthCrows > 0) + { + $aryC=mysqli_fetch_row($rslt); + $holiday_id = $aryC[0]; + $holiday_date = $aryC[1]; + $holiday_name = $aryC[2]; + if ( ($Gct_default_start < $aryC[3]) && ($Gct_default_stop > 0) ) {$Gct_default_start = $aryC[3];} + if ( ($Gct_default_stop > $aryC[4]) && ($Gct_default_stop > 0) ) {$Gct_default_stop = $aryC[4];} + if ( ($Gct_sunday_start < $aryC[3]) && ($Gct_sunday_stop > 0) ) {$Gct_sunday_start = $aryC[3];} + if ( ($Gct_sunday_stop > $aryC[4]) && ($Gct_sunday_stop > 0) ) {$Gct_sunday_stop = $aryC[4];} + if ( ($Gct_monday_start < $aryC[3]) && ($Gct_monday_stop > 0) ) {$Gct_monday_start = $aryC[3];} + if ( ($Gct_monday_stop > $aryC[4]) && ($Gct_monday_stop > 0) ) {$Gct_monday_stop = $aryC[4];} + if ( ($Gct_tuesday_start < $aryC[3]) && ($Gct_tuesday_stop > 0) ) {$Gct_tuesday_start = $aryC[3];} + if ( ($Gct_tuesday_stop > $aryC[4]) && ($Gct_tuesday_stop > 0) ) {$Gct_tuesday_stop = $aryC[4];} + if ( ($Gct_wednesday_start < $aryC[3]) && ($Gct_wednesday_stop > 0) ) {$Gct_wednesday_start = $aryC[3];} + if ( ($Gct_wednesday_stop > $aryC[4]) && ($Gct_wednesday_stop > 0) ) {$Gct_wednesday_stop = $aryC[4];} + if ( ($Gct_thursday_start < $aryC[3]) && ($Gct_thursday_stop > 0) ) {$Gct_thursday_start = $aryC[3];} + if ( ($Gct_thursday_stop > $aryC[4]) && ($Gct_thursday_stop > 0) ) {$Gct_thursday_stop = $aryC[4];} + if ( ($Gct_friday_start < $aryC[3]) && ($Gct_friday_stop > 0) ) {$Gct_friday_start = $aryC[3];} + if ( ($Gct_friday_stop > $aryC[4]) && ($Gct_friday_stop > 0) ) {$Gct_friday_stop = $aryC[4];} + if ( ($Gct_saturday_start < $aryC[3]) && ($Gct_saturday_stop > 0) ) {$Gct_saturday_start = $aryC[3];} + if ( ($Gct_saturday_stop > $aryC[4]) && ($Gct_saturday_stop > 0) ) {$Gct_saturday_stop = $aryC[4];} + if ($DB) {$dialable_output .= "LIST CALL TIME HOLIDAY FOUND! $local_call_time|$holiday_id|$holiday_date|$holiday_name|$Gct_default_start|$Gct_default_stop|\n";} + } + } + ### END Check for outbound holiday ### + + $ct_states = ''; + $ct_state_gmt_SQL = ''; + $ct_srs=0; + $b=0; + if (strlen($Gct_state_call_times)>2) + { + $state_rules = explode('|',$Gct_state_call_times); + $ct_srs = ((count($state_rules)) - 2); + } + while($ct_srs >= $b) + { + if (strlen($state_rules[$b])>1) + { + $stmt = "SELECT state_call_time_id,state_call_time_state,state_call_time_name,state_call_time_comments,sct_default_start,sct_default_stop,sct_sunday_start,sct_sunday_stop,sct_monday_start,sct_monday_stop,sct_tuesday_start,sct_tuesday_stop,sct_wednesday_start,sct_wednesday_stop,sct_thursday_start,sct_thursday_stop,sct_friday_start,sct_friday_stop,sct_saturday_start,sct_saturday_stop,ct_holidays from vicidial_state_call_times where state_call_time_id='$state_rules[$b]';"; + $rslt=mysql_to_mysqli($stmt, $link); + $sthCrows=mysqli_num_rows($rslt); + if ($sthCrows > 0) + { + $aryC=mysqli_fetch_row($rslt); + $Gstate_call_time_id = $aryC[0]; + $Gstate_call_time_state = $aryC[1]; + $Gsct_default_start = $aryC[4]; + $Gsct_default_stop = $aryC[5]; + $Gsct_sunday_start = $aryC[6]; + $Gsct_sunday_stop = $aryC[7]; + $Gsct_monday_start = $aryC[8]; + $Gsct_monday_stop = $aryC[9]; + $Gsct_tuesday_start = $aryC[10]; + $Gsct_tuesday_stop = $aryC[11]; + $Gsct_wednesday_start = $aryC[12]; + $Gsct_wednesday_stop = $aryC[13]; + $Gsct_thursday_start = $aryC[14]; + $Gsct_thursday_stop = $aryC[15]; + $Gsct_friday_start = $aryC[16]; + $Gsct_friday_stop = $aryC[17]; + $Gsct_saturday_start = $aryC[18]; + $Gsct_saturday_stop = $aryC[19]; + $Sct_holidays = $aryC[20]; + $ct_states .="'$Gstate_call_time_state',"; + } + + ### BEGIN Check for outbound state holiday ### + $Sholiday_id = ''; + if ((strlen($Sct_holidays)>2) or ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2))) + { + #Apply state holiday + if (strlen($Sct_holidays)>2) + { + $Sct_holidaysSQL = preg_replace("/\|/", "','", "$Sct_holidays"); + $Sct_holidaysSQL = "'".$Sct_holidaysSQL."'"; + $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id IN($Sct_holidaysSQL) and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; + $holidaytype = "LIST STATE CALL TIME HOLIDAY FOUND! "; + } + #Apply call time wide holiday + elseif ((strlen($holiday_id)>2) and (strlen($Sholiday_id)<2)) + { + $stmt = "SELECT holiday_id,holiday_date,holiday_name,ct_default_start,ct_default_stop from vicidial_call_time_holidays where holiday_id='$holiday_id' and holiday_status='ACTIVE' and holiday_date='$YMD' order by holiday_id;"; + $holidaytype = "LIST NO STATE HOLIDAY APPLYING CALL TIME HOLIDAY! "; + } + $rslt=mysql_to_mysqli($stmt, $link); + if ($DB) {$dialable_output .= "$stmt\n";} + $sthCrows=mysqli_num_rows($rslt); + if ($sthCrows > 0) + { + $aryC=mysqli_fetch_row($rslt); + $Sholiday_id = $aryC[0]; + $Sholiday_date = $aryC[1]; + $Sholiday_name = $aryC[2]; + if ( ($Gsct_default_start < $aryC[3]) && ($Gsct_default_stop > 0) ) {$Gsct_default_start = $aryC[3];} + if ( ($Gsct_default_stop > $aryC[4]) && ($Gsct_default_stop > 0) ) {$Gsct_default_stop = $aryC[4];} + if ( ($Gsct_sunday_start < $aryC[3]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_start = $aryC[3];} + if ( ($Gsct_sunday_stop > $aryC[4]) && ($Gsct_sunday_stop > 0) ) {$Gsct_sunday_stop = $aryC[4];} + if ( ($Gsct_monday_start < $aryC[3]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_start = $aryC[3];} + if ( ($Gsct_monday_stop > $aryC[4]) && ($Gsct_monday_stop > 0) ) {$Gsct_monday_stop = $aryC[4];} + if ( ($Gsct_tuesday_start < $aryC[3]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_start = $aryC[3];} + if ( ($Gsct_tuesday_stop > $aryC[4]) && ($Gsct_tuesday_stop > 0) ) {$Gsct_tuesday_stop = $aryC[4];} + if ( ($Gsct_wednesday_start < $aryC[3]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_start = $aryC[3];} + if ( ($Gsct_wednesday_stop > $aryC[4]) && ($Gsct_wednesday_stop > 0) ) {$Gsct_wednesday_stop = $aryC[4];} + if ( ($Gsct_thursday_start < $aryC[3]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_start = $aryC[3];} + if ( ($Gsct_thursday_stop > $aryC[4]) && ($Gsct_thursday_stop > 0) ) {$Gsct_thursday_stop = $aryC[4];} + if ( ($Gsct_friday_start < $aryC[3]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_start = $aryC[3];} + if ( ($Gsct_friday_stop > $aryC[4]) && ($Gsct_friday_stop > 0) ) {$Gsct_friday_stop = $aryC[4];} + if ( ($Gsct_saturday_start < $aryC[3]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_start = $aryC[3];} + if ( ($Gsct_saturday_stop > $aryC[4]) && ($Gsct_saturday_stop > 0) ) {$Gsct_saturday_stop = $aryC[4];} + if ($DB) {$dialable_output .= "$holidaytype |$Gstate_call_time_id|$Gstate_call_time_state|$Sholiday_id|$Sholiday_date|$Sholiday_name|$Gsct_default_start|$Gsct_default_stop|\n";} + } + } + ### END Check for outbound state holiday ### + + $r=0; + $state_gmt=''; + $del_state_gmt=''; + while($r < $g) + { + if ($GMT_day[$r]==0) #### Sunday local time + { + if (($Gsct_sunday_start==0) && ($Gsct_sunday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_sunday_start) && ($GMT_hour[$r]<$Gsct_sunday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==1) #### Monday local time + { + if (($Gsct_monday_start==0) && ($Gsct_monday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_monday_start) && ($GMT_hour[$r]<$Gsct_monday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==2) #### Tuesday local time + { + if (($Gsct_tuesday_start==0) && ($Gsct_tuesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_tuesday_start) && ($GMT_hour[$r]<$Gsct_tuesday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==3) #### Wednesday local time + { + if (($Gsct_wednesday_start==0) && ($Gsct_wednesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_wednesday_start) && ($GMT_hour[$r]<$Gsct_wednesday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==4) #### Thursday local time + { + if (($Gsct_thursday_start==0) && ($Gsct_thursday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_thursday_start) && ($GMT_hour[$r]<$Gsct_thursday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==5) #### Friday local time + { + if (($Gsct_friday_start==0) && ($Gsct_friday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_friday_start) && ($GMT_hour[$r]<$Gsct_friday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==6) #### Saturday local time + { + if (($Gsct_saturday_start==0) && ($Gsct_saturday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gsct_default_start) && ($GMT_hour[$r]<$Gsct_default_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gsct_saturday_start) && ($GMT_hour[$r]<$Gsct_saturday_stop) ) + {$state_gmt.="'$GMT_gmt[$r]',";} + } + } + $r++; + } + $state_gmt = "$state_gmt'99'"; + + $del_list_state_gmt_SQL .= "or (List_id=\"$cur_list_id\" and state='$Gstate_call_time_state' and gmt_offset_now NOT IN($state_gmt)) "; + $list_state_gmt_SQL .= "or (List_id=\"$cur_list_id\" and state='$Gstate_call_time_state' and gmt_offset_now IN($state_gmt)) "; + } + + $b++; + } + if (strlen($ct_states)>2) + { + $ct_states = preg_replace("/,$/i",'',$ct_states); + $ct_statesSQL = "and state NOT IN($ct_states)"; + } + else + { + $ct_statesSQL = ""; + } + + $r=0; + $dgA=0; + $list_default_gmt=''; + while($r < $g) + { + if ($DB > 0) + {$dialable_output .= "LCT_gmt: $r|$GMT_day[$r]|$GMT_gmt[$r]|$Gct_sunday_start|$Gct_sunday_stop|$GMT_hour[$r]|$Gct_default_start|$Gct_default_stop\n";} + + if ($GMT_day[$r]==0) #### Sunday local time + { + if (($Gct_sunday_start==0) && ($Gct_sunday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_sunday_start) && ($GMT_hour[$r]<$Gct_sunday_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==1) #### Monday local time + { + if (($Gct_monday_start==0) && ($Gct_monday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_monday_start) && ($GMT_hour[$r]<$Gct_monday_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==2) #### Tuesday local time + { + if (($Gct_tuesday_start==0) && ($Gct_tuesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_tuesday_start) && ($GMT_hour[$r]<$Gct_tuesday_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==3) #### Wednesday local time + { + if (($Gct_wednesday_start==0) && ($Gct_wednesday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_wednesday_start) && ($GMT_hour[$r]<$Gct_wednesday_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==4) #### Thursday local time + { + if (($Gct_thursday_start==0) && ($Gct_thursday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_thursday_start) && ($GMT_hour[$r]<$Gct_thursday_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==5) #### Friday local time + { + if (($Gct_friday_start==0) && ($Gct_friday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_friday_start) && ($GMT_hour[$r]<$Gct_friday_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + } + if ($GMT_day[$r]==6) #### Saturday local time + { + if (($Gct_saturday_start==0) && ($Gct_saturday_stop==0)) + { + if ( ($GMT_hour[$r]>=$Gct_default_start) && ($GMT_hour[$r]<$Gct_default_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + else + { + if ( ($GMT_hour[$r]>=$Gct_saturday_start) && ($GMT_hour[$r]<$Gct_saturday_stop) ) + {} + else + {$list_default_gmt.="'$GMT_gmt[$r]',";} + } + } + $r++; + } + + $list_default_gmt = "$list_default_gmt'99'"; + $LCTlist_id_sql .= " or ((list_id='$cur_list_id' and gmt_offset_now NOT IN($list_default_gmt) $ct_statesSQL) $list_state_gmt_SQL)"; + } + ##### END local call time for list set different than campaign ##### + + else + { + if (strlen($list_id_sql) < 3) + { + $list_id_sql = "(list_id IN('$cur_list_id'"; + } + else + { + $list_id_sql .= ",'$cur_list_id'"; + } + } + + $k++; + } + $camp_lists = preg_replace("/.$/i","",$camp_lists); + if (strlen($camp_lists) < 4) {$camp_lists="''";} + if (strlen($list_id_sql) < 4) {$list_id_sql="list_id=''";} + else {$list_id_sql .= '))';} + if (strlen($LCTlist_id_sql) > 1) {$list_id_sql .= "$LCTlist_id_sql";} + + + $stmt="SELECT count(*) FROM vicidial_list where called_since_last_reset='N' and status IN($Dsql) and list_id IN($camp_lists) and ($list_id_sql) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL $EXPsql"; + $full_dialable_SQL="called_since_last_reset='N' and status IN($Dsql) and list_id IN($camp_lists) and ($list_id_sql) and ($all_gmtSQL) $CCLsql $DLTsql $fSQL $EXPsql"; + #$DB=1; + if ($DB) {$dialable_output .= "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $rslt_rows = mysqli_num_rows($rslt); + if ($rslt_rows) + { + $rowx=mysqli_fetch_row($rslt); + $active_leads = "$rowx[0]"; + } + else {$active_leads = '0';} + + if ($DB > 0) {$dialable_output .= "|$DB|\n";} + if ( ($single_status > 0) or ($only_return > 0) ) + {return $active_leads;} + else + {$dialable_output .= _QXZ("This campaign has")." $active_leads "._QXZ("leads to be dialed in those lists")."\n";} + } + else + { + $dialable_output .= _QXZ("no dial statuses selected for this campaign")."\n"; + } + } + else + { + $dialable_output .= _QXZ("no active lists selected for this campaign")."\n"; + } + } +else + { + $dialable_output .= _QXZ("no active lists selected for this campaign")."\n"; + } + +if ($only_return < 1) + { + echo $dialable_output; + } + +##### END calculate what gmt_offset_now values are within the allowed local_call_time setting ### +} ?> diff --git a/agc_2-X/trunk/www/vicidial/help_documentation.txt b/agc_2-X/trunk/www/vicidial/help_documentation.txt index f994e2d3..8d18dcf8 100644 --- a/agc_2-X/trunk/www/vicidial/help_documentation.txt +++ b/agc_2-X/trunk/www/vicidial/help_documentation.txt @@ -1,4 +1,4 @@ -# version: 20210404162701 +# version: 20210405104301 users-user User ID This field is where you put the users ID number, can be up to 8 digits in length, Must be at least 2 characters in length. users-pass Password This field is where you put the users password. Must be at least 2 characters in length. Only letters and numbers are allowed in user passwords. A medium strength user password will be at least 10 characters in length, and a strong user password will be at least 20 characters in length and have letters as well as at least one number. It is recommended that you use a longer password if possible, stringing together several unrelated words with no spaces, and a number somewhere in the string. The maximum size of a password is 100 characters. users-force_change_password Force Change Password If this option is set to Y then the user will be prompted to change their password the next time they log in to the administration webpage or the agent screen. Default is N. @@ -146,7 +146,7 @@ campaigns-call_count_limit Call Count Limit This enforces a limit on the nu campaigns-call_count_target Call Count Target This option is only used for reporting purposes and has no effect on leads dialed. Default is 3. campaigns-daily_call_count_limit Daily Call Count Limit This feature, if enabled, will limit the number of times a lead can be called in a single day. Once a lead has reached this set limit, if the lead is selected to be dialed again, the called-since-last-reset flag on the lead will be changed to -Y- and the call will not be dialed. If you want to raise this daily limit during the day, you might need to reset your lists to be able to dial the leads that hit the previous limit earlier in the day. This feature may conflict with Auto-Alt-Dial features if they are enabled on a campaign. Default is 0 for disabled. settings-daily_limit_manual Daily Call Limit Manual If the Daily Call Count Limit is enabled, this setting will determine if manual dial calls will be counted and or restricted in the daily call count limit. The DISABLED option will not count manual dial calls or restrict them as part of the daily call count limits, only auto-dial calls would be counted restricted. If one of the COUNT options is used, then manual dial calls would be included in the daily call counts. If one of the RESTRICT options is used, then manual dial calls would be restricted as part of the daily call count limit. Default is DISABLED. -campaigns-hopper_drop_run_trigger Hopper Drop-Run Trigger This setting, if activated, will ignore all hopper loading criteria for a single hopper run for this campaign and it will only load the DROP status leads from the active lists for the campaign into the hopper at the highest hopper priority, and once this single hopper run has happened, this setting will reset to N for this campaign and the hopper loading will go back to normal for the next minute when it runs. WARNING, when this runs it will not check to see if the lists have been reset, so you may be calling back DROP leads that were recently called. However, if the Drop Lockout Time has been enabled, that setting will be honored. Default is N for inactive. +campaigns-hopper_drop_run_trigger Hopper Drop-Run Trigger This setting, if activated, will ignore all hopper loading criteria for a single hopper run for this campaign and it will only load the DROP status leads from the active lists for the campaign into the hopper at the highest hopper priority, and once this single hopper run has happened, this setting will reset to N for this campaign and the hopper loading will go back to normal for the next minute when it runs. If the -All Drops- checkbox is checked, then any status with -DROP- in the status or status name will be selected, including all system statuses and campaign statuses whether they are for outbound or inbound calls. WARNING, when this runs it will not check to see if the lists have been reset, so you may be calling back DROP leads that were recently called. However, if the Drop Lockout Time has been enabled, that setting will be honored. Default is N, unselected, for inactive. campaigns-drop_lockout_time Drop Lockout Time This is a number of hours that DROP abandon calls will be prevented from being dialed, to disable set to 0. This setting is very useful in countries like the UK where there are regulations preventing the attempted calling of customers within 72 hours of an Abandon, or DROP. Default is 0. campaigns-force_reset_hopper Force Reset of Hopper This allows you to wipe out the hopper contents upon form submission. It should be filled again when the VDhopper script runs. campaigns-dial_method Dial Method This field is the way to define how dialing is to take place. If MANUAL then the auto_dial_level will be locked at 0 unless Dial Method is changed. If RATIO then the normal dialing a number of lines for Active agents. ADAPT_HARD_LIMIT will dial predictively up to the dropped percentage and then not allow aggressive dialing once the drop limit is reached until the percentage goes down again. ADAPT_TAPERED allows for running over the dropped percentage in the first half of the shift -as defined by call_time selected for campaign- and gets more strict as the shift goes on. ADAPT_AVERAGE tries to maintain an average or the dropped percentage not imposing hard limits as aggressively as the other two methods. You cannot change the Auto Dial Level if you are in any of the ADAPT dial methods. Only the Dialer can change the dial level when in predictive dialing mode. INBOUND_MAN allows the agent to place manual dial calls from a campaign list while being able to take inbound calls between manual dial calls. diff --git a/agc_2-X/trunk/www/vicidial/non_agent_api.php b/agc_2-X/trunk/www/vicidial/non_agent_api.php index a7ce60f6..008ca8ca 100644 --- a/agc_2-X/trunk/www/vicidial/non_agent_api.php +++ b/agc_2-X/trunk/www/vicidial/non_agent_api.php @@ -175,10 +175,11 @@ # 210330-1633 - Added ability to use custom_fields_copy on update_list on a deleted list_id # 210401-1058 - Added 'custom_fields_update' option for update_list function # 210402-1102 - Added 'custom_fields_delete' option for update_list function +# 210406-1047 - Added 'dialable_count' option to list_info function # -$version = '2.14-152'; -$build = '210402-1102'; +$version = '2.14-153'; +$build = '210406-1047'; $api_url_log = 0; $startMS = microtime(); @@ -637,6 +638,8 @@ if (isset($_GET["custom_fields_update"])) {$custom_fields_update=$_GET["custom elseif (isset($_POST["custom_fields_update"])) {$custom_fields_update=$_POST["custom_fields_update"];} if (isset($_GET["custom_fields_delete"])) {$custom_fields_delete=$_GET["custom_fields_delete"];} elseif (isset($_POST["custom_fields_delete"])) {$custom_fields_delete=$_POST["custom_fields_delete"];} +if (isset($_GET["dialable_count"])) {$dialable_count=$_GET["dialable_count"];} + elseif (isset($_POST["dialable_count"])) {$dialable_count=$_POST["dialable_count"];} header ("Content-type: text/html; charset=utf-8"); header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 @@ -914,6 +917,7 @@ $field_rerank = preg_replace('/[^_0-9a-zA-Z]/','',$field_rerank); $custom_fields_add = preg_replace('/[^_0-9a-zA-Z]/','',$custom_fields_add); $custom_fields_update = preg_replace('/[^_0-9a-zA-Z]/','',$custom_fields_update); $custom_fields_delete = preg_replace('/[^_0-9a-zA-Z]/','',$custom_fields_delete); +$dialable_count = preg_replace('/[^_0-9a-zA-Z]/','',$dialable_count); $USarea = substr($phone_number, 0, 3); $USprefix = substr($phone_number, 3, 3); @@ -6433,10 +6437,50 @@ if ($function == 'list_info') $leads_counts_output .= $DL . "$all_leads_count" . $DL . "$new_leads_count"; } + $leads_dialable_output=''; + if ($dialable_count == 'Y') + { + if ($header == 'YES') + {$output .= $DL . 'dialable_count';} + + $stmt="SELECT dial_statuses,local_call_time,lead_filter_id,drop_lockout_time,call_count_limit from vicidial_campaigns where campaign_id='$campaign_id' $LOGallowed_campaignsSQL;"; + $rslt=mysql_to_mysqli($stmt, $link); + $camps_to_print = mysqli_num_rows($rslt); + if ($camps_to_print > 0) + { + $row=mysqli_fetch_row($rslt); + $dial_statuses = $row[0]; + $local_call_time = $row[1]; + $lead_filter_id = $row[2]; + $drop_lockout_time = $row[3]; + $call_count_limit = $row[4]; + } + + $stmt="SELECT lead_filter_sql from vicidial_lead_filters where lead_filter_id='$lead_filter_id';"; + $rslt=mysql_to_mysqli($stmt, $link); + $filters_to_print = mysqli_num_rows($rslt); + $filterSQL=''; + if ($filters_to_print > 0) + { + $rowx=mysqli_fetch_row($rslt); + $filterSQL = "$rowx[0]"; + } + $filterSQL = preg_replace("/\\\\/","",$filterSQL); + $filterSQL = preg_replace('/^and|and$|^or|or$/i', '',$filterSQL); + if (strlen($filterSQL)>4) + {$fSQL = "and ($filterSQL)";} + else + {$fSQL = '';} + + ### call function to calculate and print dialable leads + $single_status=0; + $only_return=1; + $leads_dialable_output = dialable_leads($DB,$link,$local_call_time,$dial_statuses,"'$list_id'",$drop_lockout_time,$call_count_limit,$single_status,$fSQL,$only_return); + } if ($header == 'YES') {$output .= "\n";} - $output .= "$list_id" . $DL . "$list_name" . $DL . "$campaign_id" . $DL . "$active" . $DL . "$list_changedate" . $DL . "$list_lastcalldate" . $DL . "$expiration_date" . $DL . "$resets_today" . $leads_counts_output . "\n"; + $output .= "$list_id" . $DL . "$list_name" . $DL . "$campaign_id" . $DL . "$active" . $DL . "$list_changedate" . $DL . "$list_lastcalldate" . $DL . "$expiration_date" . $DL . "$resets_today" . $leads_counts_output . $DL . $leads_dialable_output . "\n"; $result = 'SUCCESS'; $result_reason = "list_info LIST INFORMATION SENT";
"; +$HTML_text.=""._QXZ("$report_name")." $NWB#source_vlc_status_report$NWE\n"; + +$HTML_text.="
\n"; +$HTML_text.="
"._QXZ("Entry date").":
"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.="\n"; +$HTML_text.=""; + +$HTML_text.="\n"; + +$HTML_text.="   "; + +$HTML_text.="
"._QXZ("to")."
"; + +$HTML_text.="\n"; + +$HTML_text.="   "; + +$HTML_text.="
"._QXZ("Campaign").":
"; +$HTML_text.="

\n"; + +$HTML_text.=_QXZ("Group by").":
"; +$HTML_text.="\n"; + +$HTML_text.="
 \n"; +$HTML_text.="\n"; +$HTML_text.=_QXZ("Display as").":
"; +$HTML_text.="\n

"; + +if ($archives_available=="Y") + { + $HTML_text.=""._QXZ("Search archived data")."\n"; + } + +$HTML_text.="

\n"; + +$HTML_text.="
"; + +$report_URL="$PHP_SELF?DB=$DB&query_date=$query_date&end_date=$end_date&query_date_D=$query_date_D&query_date_T=$query_date_T&end_date_D=$end_date_D&end_date_T=$end_date_T$groupQS&SUBMIT=$SUBMIT&group_by=$group_by&search_archived_data=$search_archived_data"; + +$HTML_text.="\n"; +$HTML_text.=""._QXZ("DOWNLOAD")." |"; +$HTML_text.=" "._QXZ("REPORTS")." \n"; +$HTML_text.="\n"; +$HTML_text.="
"; +$HTML_text.="
\n\n"; + +$HTML_text.="
";
+$i=0;
+$group_string='|';
+$group_ct = count($group);
+$HTML_body="";
+
+while($i < $group_ct)
+	{
+
+	$list_stmt="select list_id from vicidial_lists where campaign_id='$group[$i]'";
+	if ($DB) {$HTML_text.="|$list_stmt|\n";}
+	$list_rslt=mysql_to_mysqli($list_stmt, $link);
+	$list_ary=array();
+	while($list_row=mysqli_fetch_row($list_rslt)) 
+		{
+		array_push($list_ary, $list_row[0]);
+		}
+
+	$dispo_ary=array();
+	$dispo_stmt="SELECT status, status_name from vicidial_campaign_statuses where campaign_id='$group[$i]' UNION SELECT status, status_name from vicidial_statuses order by status, status_name";
+	if ($DB) {$HTML_text.="|$dispo_stmt|\n";}
+	$dispo_rslt=mysql_to_mysqli($dispo_stmt, $link);
+	while($dispo_row=mysqli_fetch_row($dispo_rslt)) 
+		{
+		$dispo_ary["$dispo_row[0]"]=$dispo_row[1];
+		}
+
+	$count_ary=array();
+	$total_ary=array();
+	$status_totals=array();
+	$stmt="select lead_id, $group_by, status from ".$vicidial_list_table." where list_id in ('".implode("','", $list_ary)."') and entry_date>='$query_date' and entry_date<='$end_date'";
+	if ($DB) {$HTML_text.="|$stmt|\n";}
+	$rslt=mysql_to_mysqli($stmt, $link);
+	$grand_total=mysqli_num_rows($rslt);
+	while ($row=mysqli_fetch_row($rslt)) 
+		{
+		$count_ary["$row[1]"]["$row[2]"]++;
+		$total_ary["$row[1]"]++;
+		$status_totals["$row[2]"]++;
+		}
+	ksort($count_ary);
+	arsort($total_ary);
+	arsort($status_totals);
+
+	$HTML_body.=""._QXZ("CAMPAIGN").": $group[$i]
\n"; + $ASCII_text.=""._QXZ("CAMPAIGN").": $group[$i]\n"; + $GRAPH.=""._QXZ("CAMPAIGN").": $group[$i]\n"; + $CSV_text.="\""._QXZ("CAMPAIGN").": $group[$i]\"\n"; + + $rpt_group_title=strtoupper(preg_replace('/_/', " ", $group_by)); + + + +# while(list($key, $val)=each($count_ary)) + foreach($count_ary as $key => $val) + { + arsort($count_ary[$key]); + switch ($sort_by) + { + case "dispo_desc": + krsort($count_ary[$key]); + break; + case "dispo_asc": + ksort($count_ary[$key]); + break; + case "count_asc": + asort($count_ary[$key]); + break; + } + + $HTML_body.=""; + $HTML_body.=""; + $HTML_body.=""; + + $ASCII_text.=""._QXZ("$rpt_group_title")." : ".($key !="" ? $key : "("._QXZ("NONE").")")."\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n"; + $ASCII_text.="| "._QXZ("DISPOSITION",40)." | "._QXZ("CALLS",6)." | "._QXZ("PERCENT", 8)." |\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n"; + + # $CSV_text.="\""._QXZ("$rpt_group_title")." : ".($key !="" ? $key : "(NONE)")."\"\n"; + $CSV_text.="\""._QXZ("VENDOR LEAD CODE")."\",\""._QXZ("DISPOSITION")."\",\""._QXZ("CALLS")."\",\""._QXZ("PERCENT")."\"\n"; + + $j=0; +# while(list($key2, $val2)=each($count_ary[$key])) + foreach($count_ary[$key] as $key2 => $val2) + { + if ($j%2==0) + { + $bgcolor=$SSstd_row1_background; + } + else + { + $bgcolor=$SSstd_row2_background; + } + + $percent=sprintf("%.2f", 100*MathZDC($val2, $total_ary["$key"])); + $HTML_body.=""; + $ASCII_text.="| ".sprintf("%-40s", ($dispo_ary["$key2"] !="" ? $dispo_ary["$key2"] : $key2))." | ".sprintf("%6s", $val2)." | ".sprintf("%7s", $percent)."% |\n"; + $CSV_text.="\"".($key !="" ? $key : "("._QXZ("NONE").")")."\",\"".($dispo_ary["$key2"] !="" ? $dispo_ary["$key2"] : $key2)."\",\"".$val2."\",\"".$percent." %\"\n"; + + $j++; + } + $HTML_body.=""; + $HTML_body.="
"._QXZ("$rpt_group_title")." : ".($key !="" ? $key : "("._QXZ("NONE").")")."
"._QXZ("DISPOSITION",40).""._QXZ("CALLS",6).""._QXZ("PERCENT", 7)."
".($dispo_ary["$key2"] !="" ? $dispo_ary["$key2"] : $key2)."".$val2."".$percent." %
"._QXZ("TOTAL")."".$total_ary["$key"]." 

\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n"; + $ASCII_text.="| "._QXZ("TOTAL",40)." | ".sprintf("%6s", $total_ary["$key"])." | ".sprintf("%8s", " ")." |\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n\n"; + $CSV_text.="\"".($key !="" ? $key : "("._QXZ("NONE").")")."\",\""._QXZ("TOTAL")."\",\"".$total_ary["$key"]."\",\"\"\n\n"; + } + $i++; + + $HTML_body.=""; + $HTML_body.=""; + $HTML_body.=""; + + $ASCII_text.=""._QXZ("$rpt_group_title")." : "._QXZ("TOTALS")."\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n"; + $ASCII_text.="| "._QXZ("DISPOSITION",40)." | "._QXZ("CALLS",6)." | "._QXZ("PERCENT", 8)." |\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n"; + + # $CSV_text.="\""._QXZ("$rpt_group_title")." : TOTALS\"\n"; + $CSV_text.="\""._QXZ("VENDOR LEAD CODE")."\",\""._QXZ("DISPOSITION")."\",\""._QXZ("CALLS")."\",\""._QXZ("PERCENT")."\"\n"; + + arsort($status_totals); + switch ($sort_by) + { + case "dispo_desc": + krsort($status_totals); + break; + case "dispo_asc": + ksort($status_totals); + break; + case "count_asc": + asort($status_totals); + break; + } +# while(list($key, $val)=each($status_totals)) + foreach($status_totals as $key => $val) + { + if ($j%2==0) + { + $bgcolor=$SSstd_row1_background; + } + else + { + $bgcolor=$SSstd_row2_background; + } + + $percent=sprintf("%.2f", 100*MathZDC($val, $grand_total)); + $HTML_body.=""; + $ASCII_text.="| ".sprintf("%-40s", ($dispo_ary["$key"] !="" ? $dispo_ary["$key"] : $key))." | ".sprintf("%6s", $val)." | ".sprintf("%7s", $percent)."% |\n"; + $CSV_text.="\""._QXZ("TOTALS")."\",\"".($dispo_ary["$key"] !="" ? $dispo_ary["$key"] : $key)."\",\"".$val."\",\"".$percent." %\"\n"; + + $j++; + } + $HTML_body.=""; + $HTML_body.="
"._QXZ("$rpt_group_title")." : "._QXZ("TOTALS")."
"._QXZ("DISPOSITION",40).""._QXZ("CALLS",6).""._QXZ("PERCENT", 7)."
".($dispo_ary["$key"] !="" ? $dispo_ary["$key"] : $key)."".$val."".$percent." %
"._QXZ("GRAND TOTAL")."".$grand_total." 

\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n"; + $ASCII_text.="| "._QXZ("GRAND TOTAL",40)." | ".sprintf("%6s", $grand_total)." | ".sprintf("%8s", " ")." |\n"; + $ASCII_text.="+------------------------------------------+--------+----------+\n\n"; + $CSV_text.="\"\",\""._QXZ("GRAND TOTAL")."\",\"".$grand_total."\",\"\"\n\n"; + + } + +if ($report_display_type=="HTML") + { + $HTML_text.=$HTML_body; + } +else + { + $HTML_text.=$ASCII_text; + } + +$HTML_text.="
"; + +if ($file_download>0) + { + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "AST_campaign_status_$US$FILE_TIME.csv"; + $CSV_text=preg_replace('/\n +,/', ',', $CSV_text); + $CSV_text=preg_replace('/ +\"/', '"', $CSV_text); + $CSV_text=preg_replace('/\" +/', '"', $CSV_text); + + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + } +else + { + header("Content-type: text/html; charset=utf-8"); + + echo $HTML_head; + require("admin_header.php"); + echo $HTML_text; + flush(); + } + +if ($db_source == 'S') + { + mysqli_close($link); + $use_slave_server=0; + $db_source = 'M'; + require("dbconnect_mysqli.php"); + } + +$endMS = microtime(); +$startMSary = explode(" ",$startMS); +$endMSary = explode(" ",$endMS); +$runS = ($endMSary[0] - $startMSary[0]); +$runM = ($endMSary[1] - $startMSary[1]); +$TOTALrun = ($runS + $runM); + +$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); + +exit; + +?> diff --git a/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail.php b/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail.php index 227e5563..e6be524d 100644 --- a/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail.php +++ b/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail.php @@ -1,716 +1,716 @@ - LICENSE: AGPLv2 -# -# Gives hourly count of distinct agents per user group, with totals. -# For single days only -# -# CHANGES -# 160826-0054 - First build -# 170409-1542 - Added IP List validation code -# 170816-2026 - Added HTML formatting -# 170829-0040 - Added screen color settings -# 180507-2315 - Added new help display -# 191013-0855 - Fixes for PHP7 -# - -$startMS = microtime(); - -require("dbconnect_mysqli.php"); -require("functions.php"); - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} - elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["start_hour"])) {$start_hour=$_GET["start_hour"];} - elseif (isset($_POST["start_hour"])) {$start_hour=$_POST["start_hour"];} -if (isset($_GET["end_hour"])) {$end_hour=$_GET["end_hour"];} - elseif (isset($_POST["end_hour"])) {$end_hour=$_POST["end_hour"];} -if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} - elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["group"])) {$group=$_GET["group"];} - elseif (isset($_POST["group"])) {$group=$_POST["group"];} -if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} - elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} -if (isset($_GET["user"])) {$user=$_GET["user"];} - elseif (isset($_POST["user"])) {$user=$_POST["user"];} -if (isset($_GET["shift"])) {$shift=$_GET["shift"];} - elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} -if (isset($_GET["stage"])) {$stage=$_GET["stage"];} - elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["submit"])) {$submit=$_GET["submit"];} - elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} -if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} - elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} -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 (strlen($shift)<2) {$shift='ALL';} - -$report_name = 'User Group Hourly Report'; -$db_source = 'M'; - -############################################# -##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $non_latin = $row[0]; - $outbound_autodial_active = $row[1]; - $slave_db_server = $row[2]; - $reports_use_slave_db = $row[3]; - $SSenable_languages = $row[4]; - $SSlanguage_method = $row[5]; - $SSreport_default_format = $row[6]; - } -##### END SETTINGS LOOKUP ##### - -########################################### -if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} - -### ARCHIVED DATA CHECK CONFIGURATION -$archives_available="N"; -$log_tables_array=array("vicidial_agent_log"); -for ($t=0; $t 0) - { - $row=mysqli_fetch_row($rslt); - $VUselected_language = $row[0]; - } - -$auth=0; -$reports_auth=0; -$admin_auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth > 0) - { - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $admin_auth=$row[0]; - - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $reports_auth=$row[0]; - - if ($reports_auth < 1) - { - $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ( ($reports_auth > 0) and ($admin_auth < 1) ) - { - $ADD=999999; - $reports_only_user=1; - } - } -else - { - $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ($auth_message == 'IPBLOCK') - { - $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - -##### BEGIN log visit to the vicidial_report_log table ##### -$LOGip = getenv("REMOTE_ADDR"); -$LOGbrowser = getenv("HTTP_USER_AGENT"); -$LOGscript_name = getenv("SCRIPT_NAME"); -$LOGserver_name = getenv("SERVER_NAME"); -$LOGserver_port = getenv("SERVER_PORT"); -$LOGrequest_uri = getenv("REQUEST_URI"); -$LOGhttp_referer = getenv("HTTP_REFERER"); -$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); -$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); -$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); -if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} -else {$LOGserver_port = ":$LOGserver_port";} -$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; - -$LOGhostname = php_uname('n'); -if (strlen($LOGhostname)<1) {$LOGhostname='X';} -if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} - -$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$webserver_id_ct = mysqli_num_rows($rslt); -if ($webserver_id_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $webserver_id = $row[0]; - } -else - { - ##### insert webserver entry - $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $affected_rows = mysqli_affected_rows($link); - $webserver_id = mysqli_insert_id($link); - } - -$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$report_log_id = mysqli_insert_id($link); -##### END log visit to the vicidial_report_log table ##### - -if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) - { - mysqli_close($link); - $use_slave_server=1; - $db_source = 'S'; - require("dbconnect_mysqli.php"); - echo "\n"; - } - -$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGuser_group = $row[0]; - -$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGallowed_campaigns = $row[0]; -$LOGallowed_reports = $row[1]; -$LOGadmin_viewable_groups = $row[2]; -$LOGadmin_viewable_call_times = $row[3]; - -if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) - { - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; - exit; - } - -$LOGallowed_campaignsSQL=''; -$whereLOGallowed_campaignsSQL=''; -if ( (!preg_match('/\-ALL/i', $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')"; - } -$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; - -$LOGadmin_viewable_groupsSQL=''; -$vuLOGadmin_viewable_groupsSQL=''; -$whereLOGadmin_viewable_groupsSQL=''; -if ( (!preg_match('/\-\-ALL\-\-/i',$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')"; - $vuLOGadmin_viewable_groupsSQL = "and vicidial_users.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; - } - -$LOGadmin_viewable_call_timesSQL=''; -$whereLOGadmin_viewable_call_timesSQL=''; -if ( (!preg_match('/\-\-ALL\-\-/i', $LOGadmin_viewable_call_times)) and (strlen($LOGadmin_viewable_call_times) > 3) ) - { - $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ -/",'',$LOGadmin_viewable_call_times); - $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_call_timesSQL); - $LOGadmin_viewable_call_timesSQL = "and call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; - $whereLOGadmin_viewable_call_timesSQL = "where call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; - } - -$MT[0]=''; -$NOW_DATE = date("Y-m-d"); -$NOW_TIME = date("Y-m-d H:i:s"); -$STARTtime = date("U"); -if (!isset($group)) {$group = array();} -if (!isset($user_group)) {$user_group = array();} -if (!isset($query_date)) {$query_date = $NOW_DATE;} -if (!isset($start_hour)) {$start_hour = date("H");} -if (!isset($end_hour)) {$end_hour = date("H");} - - -$stmt="select user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$user_groups_to_print = mysqli_num_rows($rslt); -$i=0; -$user_groups=array(); -while ($i < $user_groups_to_print) - { - $row=mysqli_fetch_row($rslt); - $user_groups[$i] =$row[0]; - $i++; - } - -$i=0; -$user_group_string='|'; -$user_group_ct = count($user_group); -while($i < $user_group_ct) - { - $user_group_string .= "$user_group[$i]|"; - $user_group_SQL .= "'$user_group[$i]',"; - $user_groupQS .= "&user_group[]=$user_group[$i]"; - $i++; - } -if ( (preg_match("/--ALL--/",$user_group_string) ) or ($user_group_ct < 1) ) - {$user_group_SQL = "";} -else - { - $user_group_SQL = preg_replace("/,\$/",'',$user_group_SQL); - $user_group_SQL_str=$user_group_SQL; - $user_group_SQL = "and user_group IN($user_group_SQL)"; - } - - - -$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$campaigns_to_print = mysqli_num_rows($rslt); -$i=0; -$groups=array(); -while ($i < $campaigns_to_print) - { - $row=mysqli_fetch_row($rslt); - $groups[$i] =$row[0]; - $i++; - } - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) - { - $group_string .= "$group[$i]|"; - $group_SQL .= "'$group[$i]',"; - $groupQS .= "&group[]=$group[$i]"; - } - $i++; - } - -if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) - {$group_SQL = "";} -else - { - $group_SQL = preg_replace("/,\$/",'',$group_SQL); - $group_SQL_str=$group_SQL; - $group_SQL = "and campaign_id IN($group_SQL)"; - } - -$LINKbase = "$PHP_SELF?query_date=$query_date&end_date=$end_date&shift=$shift&DB=$DB&user=$user$groupQS&search_archived_data=$search_archived_data&report_display_type=$report_display_type"; - -require("screen_colors.php"); - -# $NWB = "   \"HELP\""; - -$NWB = "\"HELP\""; - -if ($file_download < 1) - { - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo ""; - - echo "\n"; - echo "\n"; - echo "\n"; - # require("chart_button.php"); - # echo "\n"; - # echo "\n"; - - echo "\n"; - echo ""._QXZ("$report_name")."\n"; - echo ""; - - $short_header=1; - - require("admin_header.php"); - - echo "\n"; - echo "\n"; - echo ""._QXZ("$report_name")." $NWB#user_group_hourly_detail$NWE\n"; - echo "
";
-	}
-
-
-
-if ($SUBMIT && $query_date && $start_hour && $end_hour) {
-
-	$CSV_text .= "\""._QXZ("$report_name",24).":  $NOW_TIME ($db_source)\"\n\n";
-	$CSV_text .= "\""._QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\"\n";
-	$CSV_text .= "\""._QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\"\n";
-	$CSV_text .= "\""._QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\"\n\n";
-
-	$ASCII_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
-	$ASCII_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
-	$ASCII_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
-	$ASCII_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
-
-	$HTML_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
-	$HTML_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
-	$HTML_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
-	$HTML_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
-
-	$stmt="select user_group, substr(event_time, 12,2) as hour, count(distinct user) as ct from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL group by user_group, hour order by hour, user_group";
-	if ($DB) {$ASCII_text.=$stmt."\n";}
-	$rslt=mysql_to_mysqli($stmt, $link);
-
-	# select user_group, substr(event_time, 12,2) as hour, count(distinct user) as ct from ".$vicidial_agent_log_table." where ((event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59') or  (event_time+INTERVAL (pause_sec+wait_sec+talk_sec+dispo_sec) SECOND>='$query_date $start_hour:00:00' and event_time+INTERVAL (pause_sec+wait_sec+talk_sec+dispo_sec) SECOND<='$query_date $end_hour:59:59')) $group_SQL $user_group_SQL group by user_group, hour order by user_group, hour
-
-	$user_group_array=array();
-	$hour_array=array();
-	$hour_total_array=array();
-	$usergroup_total_array=array();
-	while($row=mysqli_fetch_array($rslt)) {
-		$user_group_array[$row["user_group"]]+=$row["ct"];
-		$hour_array[$row["hour"]]+=$row["ct"];
-		$hour_total_array[$row["user_group"]][$row["hour"]]+=$row["ct"];  # For ASCII/CSV output
-		$usergroup_total_array[$row["hour"]][$row["user_group"]]+=$row["ct"]; # For GRAPH output
-	}
-
-	$total_stmt="select user_group, count(distinct user) as ct from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL group by user_group order by user_group";
-	$total_rslt=mysql_to_mysqli($total_stmt, $link);
-	$total_array=array();
-	while ($total_row=mysqli_fetch_array($total_rslt)) {
-		$total_array[$total_row["user_group"]]+=$total_row["ct"];
-	}
-
-	$grand_total_stmt="select distinct user from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL";
-	$grand_total_rslt=mysql_to_mysqli($grand_total_stmt, $link);
-	$grand_total=mysqli_num_rows($grand_total_rslt);
-
-	$ASCII_header ="+----------------------+--------+";
-	$ASCII_title .="| "._QXZ("USER GROUP", 20)." | "._QXZ("AGENTS", 6)." |";
-	$ASCII_total .="|               "._QXZ("TOTALS", 6)." | ".sprintf("%6s", $grand_total)." |";
-
-	$table_columns=2;
-	$HTML_text.="";
-	$HTML_text.="";
-	$HTML_text.="";
-	$HTML_text.="";
-
-	$HTML_text2.="";
-	$HTML_text2.="";
-	$HTML_text2.="";
-
-	$CSV_text.="\""._QXZ("USER GROUP")."\",\""._QXZ("AGENTS")."\"";
-	$CSV_total.="\""._QXZ("TOTALS")."\",\"$grand_total\"";
-
-	# while (list($key, $val)=each($hour_array)) {	
-	foreach($hour_array as $key => $val) {
-		$ASCII_title.=" ".date("ha", strtotime("$key:00"))." to ";
-		$key1=$key+1;
-		$ASCII_title.=date("ha", strtotime("$key1:00"))." |";
-		$ASCII_header.="--------------+";
-		$ASCII_total.=" ".sprintf("%12s", ($hour_array[$key]+0))." |";
-
-		$HTML_text.="";
-		$HTML_text2.="";
-		$table_columns++;
-
-		$CSV_text.=",\"".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."\"";
-		$CSV_total.=",\"".($hour_array[$key]+0)."\"";
-	}
-	reset($hour_array);
-	reset($user_group_array);
-
-	# print_r($user_group_array);
-	# print_r($hour_array);
-	# print_r($total_array);
-
-	$ASCII_text.=$ASCII_header."\n";
-	$ASCII_text.=$ASCII_title."\n";
-	$ASCII_text.=$ASCII_header."\n";
-
-	$HTML_text.="\n";
-
-	$CSV_text.="\n";
-
-	#while (list($key, $val)=each($user_group_array)) {
-	foreach ($user_group_array as $key => $val) {
-		$ASCII_text.="| ".sprintf("%20s", $key)." | ".sprintf("%6s", $total_array[$key])." |";
-		$HTML_text.="";
-		$HTML_text.="";
-		$HTML_text.="";
-
-		$CSV_text.="\"$key\",\"".$total_array[$key]."\"";
-		# while (list($key2, $val2)=each($hour_array)) {	
-		foreach($hour_array as $key2 => $val2) {
-			$ASCII_text.=" ".sprintf("%12s", ($hour_total_array[$key][$key2]+0))." |";
-			$HTML_text.="";
-			$CSV_text.=",\"".($hour_total_array[$key][$key2]+0)."\"";
-		}
-		reset($hour_array);
-		$CSV_text.="\n";
-		$HTML_text.="\n";
-		$ASCII_text.="\n";
-
-	}
-
-	$ASCII_text.=$ASCII_header."\n";
-	$ASCII_text.=$ASCII_total."\n";
-	$ASCII_text.=$ASCII_header."\n";
-
-	$HTML_text2.="";
-	$HTML_text2.="
"._QXZ("USER GROUP").""._QXZ("AGENTS")."
"._QXZ("TOTALS")."".$grand_total."".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."".($hour_array[$key]+0)."
".$key." ".$total_array[$key]." ".($hour_total_array[$key][$key2]+0)."
"; - $HTML_text.=$HTML_text2; - - $CSV_text.=$CSV_total."\n"; -} - - -if ($file_download > 0) - { - $US='_'; - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "USER_GROUP_HOURLY_DETAIL_$US$FILE_TIME.csv"; - - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - - // It will be called LIST_101_20090209-121212.txt - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - - if ($db_source == 'S') - { - mysqli_close($link); - $use_slave_server=0; - $db_source = 'M'; - require("dbconnect_mysqli.php"); - } - - $endMS = microtime(); - $startMSary = explode(" ",$startMS); - $endMSary = explode(" ",$endMS); - $runS = ($endMSary[0] - $startMSary[0]); - $runM = ($endMSary[1] - $startMSary[1]); - $TOTALrun = ($runS + $runM); - - $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - - exit; - } - - -echo "
"; -echo "\n"; - -echo ""; -echo ""; -echo "
"._QXZ("Date").":
"; -echo "\n"; -echo ""; -?> - - - - "._QXZ("Campaigns").":
"; -echo "\n"; - -echo "
"._QXZ("Teams/User Groups").":
"; -echo "\n"; -echo "
\n"; - -echo _QXZ("Display as:")."
"; -echo "\n

"; - -if ($archives_available=="Y") - { - echo ""._QXZ("Search archived data")."\n"; - } - -echo "

\n"; -echo "
        "; - -echo "          \n"; -echo ""._QXZ("DOWNLOAD")." |"; -echo " "._QXZ("REPORTS")." | v2\n"; -echo "\n"; -echo "
"._QXZ("Start time").": :00:00"; - -echo "
"._QXZ("End time").": :59:59"; -echo "
"; - -echo "
"; - -if ($report_display_type=="HTML") - { - echo $HTML_text; - } -else - { - echo $ASCII_text; - } - - -echo "\n"; -?> + LICENSE: AGPLv2 +# +# Gives hourly count of distinct agents per user group, with totals. +# For single days only +# +# CHANGES +# 160826-0054 - First build +# 170409-1542 - Added IP List validation code +# 170816-2026 - Added HTML formatting +# 170829-0040 - Added screen color settings +# 180507-2315 - Added new help display +# 191013-0855 - Fixes for PHP7 +# + +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["start_hour"])) {$start_hour=$_GET["start_hour"];} + elseif (isset($_POST["start_hour"])) {$start_hour=$_POST["start_hour"];} +if (isset($_GET["end_hour"])) {$end_hour=$_GET["end_hour"];} + elseif (isset($_POST["end_hour"])) {$end_hour=$_POST["end_hour"];} +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} + elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} +if (isset($_GET["user"])) {$user=$_GET["user"];} + elseif (isset($_POST["user"])) {$user=$_POST["user"];} +if (isset($_GET["shift"])) {$shift=$_GET["shift"];} + elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} +if (isset($_GET["stage"])) {$stage=$_GET["stage"];} + elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} + elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} +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 (strlen($shift)<2) {$shift='ALL';} + +$report_name = 'User Group Hourly Report'; +$db_source = 'M'; + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $SSenable_languages = $row[4]; + $SSlanguage_method = $row[5]; + $SSreport_default_format = $row[6]; + } +##### END SETTINGS LOOKUP ##### + +########################################### +if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} + +### ARCHIVED DATA CHECK CONFIGURATION +$archives_available="N"; +$log_tables_array=array("vicidial_agent_log"); +for ($t=0; $t 0) + { + $row=mysqli_fetch_row($rslt); + $VUselected_language = $row[0]; + } + +$auth=0; +$reports_auth=0; +$admin_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $admin_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + if ($reports_auth < 1) + { + $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( ($reports_auth > 0) and ($admin_auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ($auth_message == 'IPBLOCK') + { + $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +##### BEGIN log visit to the vicidial_report_log table ##### +$LOGip = getenv("REMOTE_ADDR"); +$LOGbrowser = getenv("HTTP_USER_AGENT"); +$LOGscript_name = getenv("SCRIPT_NAME"); +$LOGserver_name = getenv("SERVER_NAME"); +$LOGserver_port = getenv("SERVER_PORT"); +$LOGrequest_uri = getenv("REQUEST_URI"); +$LOGhttp_referer = getenv("HTTP_REFERER"); +$LOGbrowser=preg_replace("/\'|\"|\\\\/","",$LOGbrowser); +$LOGrequest_uri=preg_replace("/\'|\"|\\\\/","",$LOGrequest_uri); +$LOGhttp_referer=preg_replace("/\'|\"|\\\\/","",$LOGhttp_referer); +if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} +else {$LOGserver_port = ":$LOGserver_port";} +$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; + +$LOGhostname = php_uname('n'); +if (strlen($LOGhostname)<1) {$LOGhostname='X';} +if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} + +$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$webserver_id_ct = mysqli_num_rows($rslt); +if ($webserver_id_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $webserver_id = $row[0]; + } +else + { + ##### insert webserver entry + $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $affected_rows = mysqli_affected_rows($link); + $webserver_id = mysqli_insert_id($link); + } + +$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$report_log_id = mysqli_insert_id($link); +##### END log visit to the vicidial_report_log table ##### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysqli_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect_mysqli.php"); + echo "\n"; + } + +$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGuser_group = $row[0]; + +$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGallowed_campaigns = $row[0]; +$LOGallowed_reports = $row[1]; +$LOGadmin_viewable_groups = $row[2]; +$LOGadmin_viewable_call_times = $row[3]; + +if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) + { + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; + exit; + } + +$LOGallowed_campaignsSQL=''; +$whereLOGallowed_campaignsSQL=''; +if ( (!preg_match('/\-ALL/i', $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')"; + } +$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; + +$LOGadmin_viewable_groupsSQL=''; +$vuLOGadmin_viewable_groupsSQL=''; +$whereLOGadmin_viewable_groupsSQL=''; +if ( (!preg_match('/\-\-ALL\-\-/i',$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')"; + $vuLOGadmin_viewable_groupsSQL = "and vicidial_users.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; + } + +$LOGadmin_viewable_call_timesSQL=''; +$whereLOGadmin_viewable_call_timesSQL=''; +if ( (!preg_match('/\-\-ALL\-\-/i', $LOGadmin_viewable_call_times)) and (strlen($LOGadmin_viewable_call_times) > 3) ) + { + $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ -/",'',$LOGadmin_viewable_call_times); + $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_call_timesSQL); + $LOGadmin_viewable_call_timesSQL = "and call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; + $whereLOGadmin_viewable_call_timesSQL = "where call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; + } + +$MT[0]=''; +$NOW_DATE = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$STARTtime = date("U"); +if (!isset($group)) {$group = array();} +if (!isset($user_group)) {$user_group = array();} +if (!isset($query_date)) {$query_date = $NOW_DATE;} +if (!isset($start_hour)) {$start_hour = date("H");} +if (!isset($end_hour)) {$end_hour = date("H");} + + +$stmt="select user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$user_groups_to_print = mysqli_num_rows($rslt); +$i=0; +$user_groups=array(); +while ($i < $user_groups_to_print) + { + $row=mysqli_fetch_row($rslt); + $user_groups[$i] =$row[0]; + $i++; + } + +$i=0; +$user_group_string='|'; +$user_group_ct = count($user_group); +while($i < $user_group_ct) + { + $user_group_string .= "$user_group[$i]|"; + $user_group_SQL .= "'$user_group[$i]',"; + $user_groupQS .= "&user_group[]=$user_group[$i]"; + $i++; + } +if ( (preg_match("/--ALL--/",$user_group_string) ) or ($user_group_ct < 1) ) + {$user_group_SQL = "";} +else + { + $user_group_SQL = preg_replace("/,\$/",'',$user_group_SQL); + $user_group_SQL_str=$user_group_SQL; + $user_group_SQL = "and user_group IN($user_group_SQL)"; + } + + + +$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$campaigns_to_print = mysqli_num_rows($rslt); +$i=0; +$groups=array(); +while ($i < $campaigns_to_print) + { + $row=mysqli_fetch_row($rslt); + $groups[$i] =$row[0]; + $i++; + } + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) + { + $group_string .= "$group[$i]|"; + $group_SQL .= "'$group[$i]',"; + $groupQS .= "&group[]=$group[$i]"; + } + $i++; + } + +if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) + {$group_SQL = "";} +else + { + $group_SQL = preg_replace("/,\$/",'',$group_SQL); + $group_SQL_str=$group_SQL; + $group_SQL = "and campaign_id IN($group_SQL)"; + } + +$LINKbase = "$PHP_SELF?query_date=$query_date&end_date=$end_date&shift=$shift&DB=$DB&user=$user$groupQS&search_archived_data=$search_archived_data&report_display_type=$report_display_type"; + +require("screen_colors.php"); + +# $NWB = "   \"HELP\""; + +$NWB = "\"HELP\""; + +if ($file_download < 1) + { + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo ""; + + echo "\n"; + echo "\n"; + echo "\n"; + # require("chart_button.php"); + # echo "\n"; + # echo "\n"; + + echo "\n"; + echo ""._QXZ("$report_name")."\n"; + echo ""; + + $short_header=1; + + require("admin_header.php"); + + echo "\n"; + echo "\n"; + echo ""._QXZ("$report_name")." $NWB#user_group_hourly_detail$NWE\n"; + echo "
";
+	}
+
+
+
+if ($SUBMIT && $query_date && $start_hour && $end_hour) {
+
+	$CSV_text .= "\""._QXZ("$report_name",24).":  $NOW_TIME ($db_source)\"\n\n";
+	$CSV_text .= "\""._QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\"\n";
+	$CSV_text .= "\""._QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\"\n";
+	$CSV_text .= "\""._QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\"\n\n";
+
+	$ASCII_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
+	$ASCII_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
+	$ASCII_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
+	$ASCII_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
+
+	$HTML_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
+	$HTML_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
+	$HTML_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
+	$HTML_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
+
+	$stmt="select user_group, substr(event_time, 12,2) as hour, count(distinct user) as ct from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL group by user_group, hour order by hour, user_group";
+	if ($DB) {$ASCII_text.=$stmt."\n";}
+	$rslt=mysql_to_mysqli($stmt, $link);
+
+	# select user_group, substr(event_time, 12,2) as hour, count(distinct user) as ct from ".$vicidial_agent_log_table." where ((event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59') or  (event_time+INTERVAL (pause_sec+wait_sec+talk_sec+dispo_sec) SECOND>='$query_date $start_hour:00:00' and event_time+INTERVAL (pause_sec+wait_sec+talk_sec+dispo_sec) SECOND<='$query_date $end_hour:59:59')) $group_SQL $user_group_SQL group by user_group, hour order by user_group, hour
+
+	$user_group_array=array();
+	$hour_array=array();
+	$hour_total_array=array();
+	$usergroup_total_array=array();
+	while($row=mysqli_fetch_array($rslt)) {
+		$user_group_array[$row["user_group"]]+=$row["ct"];
+		$hour_array[$row["hour"]]+=$row["ct"];
+		$hour_total_array[$row["user_group"]][$row["hour"]]+=$row["ct"];  # For ASCII/CSV output
+		$usergroup_total_array[$row["hour"]][$row["user_group"]]+=$row["ct"]; # For GRAPH output
+	}
+
+	$total_stmt="select user_group, count(distinct user) as ct from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL group by user_group order by user_group";
+	$total_rslt=mysql_to_mysqli($total_stmt, $link);
+	$total_array=array();
+	while ($total_row=mysqli_fetch_array($total_rslt)) {
+		$total_array[$total_row["user_group"]]+=$total_row["ct"];
+	}
+
+	$grand_total_stmt="select distinct user from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL";
+	$grand_total_rslt=mysql_to_mysqli($grand_total_stmt, $link);
+	$grand_total=mysqli_num_rows($grand_total_rslt);
+
+	$ASCII_header ="+----------------------+--------+";
+	$ASCII_title .="| "._QXZ("USER GROUP", 20)." | "._QXZ("AGENTS", 6)." |";
+	$ASCII_total .="|               "._QXZ("TOTALS", 6)." | ".sprintf("%6s", $grand_total)." |";
+
+	$table_columns=2;
+	$HTML_text.="";
+	$HTML_text.="";
+	$HTML_text.="";
+	$HTML_text.="";
+
+	$HTML_text2.="";
+	$HTML_text2.="";
+	$HTML_text2.="";
+
+	$CSV_text.="\""._QXZ("USER GROUP")."\",\""._QXZ("AGENTS")."\"";
+	$CSV_total.="\""._QXZ("TOTALS")."\",\"$grand_total\"";
+
+	# while (list($key, $val)=each($hour_array)) {	
+	foreach($hour_array as $key => $val) {
+		$ASCII_title.=" ".date("ha", strtotime("$key:00"))." to ";
+		$key1=$key+1;
+		$ASCII_title.=date("ha", strtotime("$key1:00"))." |";
+		$ASCII_header.="--------------+";
+		$ASCII_total.=" ".sprintf("%12s", ($hour_array[$key]+0))." |";
+
+		$HTML_text.="";
+		$HTML_text2.="";
+		$table_columns++;
+
+		$CSV_text.=",\"".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."\"";
+		$CSV_total.=",\"".($hour_array[$key]+0)."\"";
+	}
+	reset($hour_array);
+	reset($user_group_array);
+
+	# print_r($user_group_array);
+	# print_r($hour_array);
+	# print_r($total_array);
+
+	$ASCII_text.=$ASCII_header."\n";
+	$ASCII_text.=$ASCII_title."\n";
+	$ASCII_text.=$ASCII_header."\n";
+
+	$HTML_text.="\n";
+
+	$CSV_text.="\n";
+
+	#while (list($key, $val)=each($user_group_array)) {
+	foreach ($user_group_array as $key => $val) {
+		$ASCII_text.="| ".sprintf("%20s", $key)." | ".sprintf("%6s", $total_array[$key])." |";
+		$HTML_text.="";
+		$HTML_text.="";
+		$HTML_text.="";
+
+		$CSV_text.="\"$key\",\"".$total_array[$key]."\"";
+		# while (list($key2, $val2)=each($hour_array)) {	
+		foreach($hour_array as $key2 => $val2) {
+			$ASCII_text.=" ".sprintf("%12s", ($hour_total_array[$key][$key2]+0))." |";
+			$HTML_text.="";
+			$CSV_text.=",\"".($hour_total_array[$key][$key2]+0)."\"";
+		}
+		reset($hour_array);
+		$CSV_text.="\n";
+		$HTML_text.="\n";
+		$ASCII_text.="\n";
+
+	}
+
+	$ASCII_text.=$ASCII_header."\n";
+	$ASCII_text.=$ASCII_total."\n";
+	$ASCII_text.=$ASCII_header."\n";
+
+	$HTML_text2.="";
+	$HTML_text2.="
"._QXZ("USER GROUP").""._QXZ("AGENTS")."
"._QXZ("TOTALS")."".$grand_total."".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."".($hour_array[$key]+0)."
".$key." ".$total_array[$key]." ".($hour_total_array[$key][$key2]+0)."
"; + $HTML_text.=$HTML_text2; + + $CSV_text.=$CSV_total."\n"; +} + + +if ($file_download > 0) + { + $US='_'; + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "USER_GROUP_HOURLY_DETAIL_$US$FILE_TIME.csv"; + + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + + if ($db_source == 'S') + { + mysqli_close($link); + $use_slave_server=0; + $db_source = 'M'; + require("dbconnect_mysqli.php"); + } + + $endMS = microtime(); + $startMSary = explode(" ",$startMS); + $endMSary = explode(" ",$endMS); + $runS = ($endMSary[0] - $startMSary[0]); + $runM = ($endMSary[1] - $startMSary[1]); + $TOTALrun = ($runS + $runM); + + $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + + exit; + } + + +echo "
"; +echo "\n"; + +echo ""; +echo ""; +echo "
"._QXZ("Date").":
"; +echo "\n"; +echo ""; +?> + + + + "._QXZ("Campaigns").":
"; +echo "\n"; + +echo "
"._QXZ("Teams/User Groups").":
"; +echo "\n"; +echo "
\n"; + +echo _QXZ("Display as:")."
"; +echo "\n

"; + +if ($archives_available=="Y") + { + echo ""._QXZ("Search archived data")."\n"; + } + +echo "

\n"; +echo "
        "; + +echo "          \n"; +echo ""._QXZ("DOWNLOAD")." |"; +echo " "._QXZ("REPORTS")." | v2\n"; +echo "\n"; +echo "
"._QXZ("Start time").": :00:00"; + +echo "
"._QXZ("End time").": :59:59"; +echo "
"; + +echo "
"; + +if ($report_display_type=="HTML") + { + echo $HTML_text; + } +else + { + echo $ASCII_text; + } + + +echo "\n"; +?> diff --git a/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail_v2.php b/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail_v2.php index e02c4df0..25e344ad 100644 --- a/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail_v2.php +++ b/agc_2-X/trunk/www/vicidial/AST_user_group_hourly_detail_v2.php @@ -1,743 +1,743 @@ - -# Joseph Johnson -# Matt Florell -# -# Thanks to Joseph Johnson LICENSE: AGPLv2 -# I took his report as base for this one. -# -# Gives hourly detail of distinct agents per user group, with totals. -# For single days only -# -# CHANGES -# 170816-2012 - First build -# 170816-2152 - Added HTML option -# 170818-0749 - Added upgraded code, fixes and link to v1 of report -# 170829-0040 - Added screen color settings -# 180507-2315 - Added new help display -# 191013-0816 - Fixes for PHP7 -# - -$startMS = microtime(); - -require("dbconnect_mysqli.php"); -require("functions.php"); - -$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; -$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; -$PHP_SELF=$_SERVER['PHP_SELF']; -if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} - elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["start_hour"])) {$start_hour=$_GET["start_hour"];} - elseif (isset($_POST["start_hour"])) {$start_hour=$_POST["start_hour"];} -if (isset($_GET["end_hour"])) {$end_hour=$_GET["end_hour"];} - elseif (isset($_POST["end_hour"])) {$end_hour=$_POST["end_hour"];} -if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} - elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} -if (isset($_GET["group"])) {$group=$_GET["group"];} - elseif (isset($_POST["group"])) {$group=$_POST["group"];} -if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} - elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} -if (isset($_GET["user"])) {$user=$_GET["user"];} - elseif (isset($_POST["user"])) {$user=$_POST["user"];} -if (isset($_GET["shift"])) {$shift=$_GET["shift"];} - elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} -if (isset($_GET["stage"])) {$stage=$_GET["stage"];} - elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} -if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} - elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} -if (isset($_GET["DB"])) {$DB=$_GET["DB"];} - elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} -if (isset($_GET["submit"])) {$submit=$_GET["submit"];} - elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} -if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} - elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} -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 (strlen($shift)<2) {$shift='ALL';} - -$report_name = 'User Group Detail Hourly Report'; -$db_source = 'M'; - -############################################# -##### START SYSTEM_SETTINGS LOOKUP ##### -$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$qm_conf_ct = mysqli_num_rows($rslt); -if ($qm_conf_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $non_latin = $row[0]; - $outbound_autodial_active = $row[1]; - $slave_db_server = $row[2]; - $reports_use_slave_db = $row[3]; - $SSenable_languages = $row[4]; - $SSlanguage_method = $row[5]; - $SSreport_default_format = $row[6]; - } -##### END SETTINGS LOOKUP ##### - -########################################### -if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} - -### ARCHIVED DATA CHECK CONFIGURATION -$archives_available="N"; -$log_tables_array=array("vicidial_agent_log"); -for ($t=0; $t 0) - { - $row=mysqli_fetch_row($rslt); - $VUselected_language = $row[0]; - } - -$auth=0; -$reports_auth=0; -$admin_auth=0; -$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); -if ($auth_message == 'GOOD') - {$auth=1;} - -if ($auth > 0) - { - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $admin_auth=$row[0]; - - $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $row=mysqli_fetch_row($rslt); - $reports_auth=$row[0]; - - if ($reports_auth < 1) - { - $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - if ( ($reports_auth > 0) and ($admin_auth < 1) ) - { - $ADD=999999; - $reports_only_user=1; - } - } -else - { - $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); - if ($auth_message == 'LOCK') - { - $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); - Header ("Content-type: text/html; charset=utf-8"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; - exit; - } - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; - exit; - } - -##### BEGIN log visit to the vicidial_report_log table ##### -$LOGip = getenv("REMOTE_ADDR"); -$LOGbrowser = getenv("HTTP_USER_AGENT"); -$LOGscript_name = getenv("SCRIPT_NAME"); -$LOGserver_name = getenv("SERVER_NAME"); -$LOGserver_port = getenv("SERVER_PORT"); -$LOGrequest_uri = getenv("REQUEST_URI"); -$LOGhttp_referer = getenv("HTTP_REFERER"); -if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} - else {$HTTPprotocol = 'http://';} -if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} -else {$LOGserver_port = ":$LOGserver_port";} -$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; - -$LOGhostname = php_uname('n'); -if (strlen($LOGhostname)<1) {$LOGhostname='X';} -if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} - -$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {echo "$stmt\n";} -$webserver_id_ct = mysqli_num_rows($rslt); -if ($webserver_id_ct > 0) - { - $row=mysqli_fetch_row($rslt); - $webserver_id = $row[0]; - } -else - { - ##### insert webserver entry - $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; - if ($DB) {echo "$stmt\n";} - $rslt=mysql_to_mysqli($stmt, $link); - $affected_rows = mysqli_affected_rows($link); - $webserver_id = mysqli_insert_id($link); - } - -$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$report_log_id = mysqli_insert_id($link); -##### END log visit to the vicidial_report_log table ##### - -if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) - { - mysqli_close($link); - $use_slave_server=1; - $db_source = 'S'; - require("dbconnect_mysqli.php"); - echo "\n"; - } - -$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGuser_group = $row[0]; - -$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';"; -if ($DB) {echo "|$stmt|\n";} -$rslt=mysql_to_mysqli($stmt, $link); -$row=mysqli_fetch_row($rslt); -$LOGallowed_campaigns = $row[0]; -$LOGallowed_reports = $row[1]; -$LOGadmin_viewable_groups = $row[2]; -$LOGadmin_viewable_call_times = $row[3]; - -if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) - { - Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); - Header("HTTP/1.0 401 Unauthorized"); - echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; - exit; - } - -$LOGallowed_campaignsSQL=''; -$whereLOGallowed_campaignsSQL=''; -if ( (!preg_match('/\-ALL/i', $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')"; - } -$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; - -$LOGadmin_viewable_groupsSQL=''; -$vuLOGadmin_viewable_groupsSQL=''; -$whereLOGadmin_viewable_groupsSQL=''; -if ( (!preg_match('/\-\-ALL\-\-/i',$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')"; - $vuLOGadmin_viewable_groupsSQL = "and vicidial_users.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; - } - -$LOGadmin_viewable_call_timesSQL=''; -$whereLOGadmin_viewable_call_timesSQL=''; -if ( (!preg_match('/\-\-ALL\-\-/i', $LOGadmin_viewable_call_times)) and (strlen($LOGadmin_viewable_call_times) > 3) ) - { - $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ -/",'',$LOGadmin_viewable_call_times); - $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_call_timesSQL); - $LOGadmin_viewable_call_timesSQL = "and call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; - $whereLOGadmin_viewable_call_timesSQL = "where call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; - } - -$MT[0]=''; -$NOW_DATE = date("Y-m-d"); -$NOW_TIME = date("Y-m-d H:i:s"); -$STARTtime = date("U"); -if (!isset($group)) {$group = array();} -if (!isset($user_group)) {$user_group = array();} -if (!isset($query_date)) {$query_date = $NOW_DATE;} -if (!isset($start_hour)) {$start_hour = date("H");} -if (!isset($end_hour)) {$end_hour = date("H");} - - -$stmt="select user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$user_groups_to_print = mysqli_num_rows($rslt); -$i=0; -$user_groups=array(); -while ($i < $user_groups_to_print) - { - $row=mysqli_fetch_row($rslt); - $user_groups[$i] =$row[0]; - $i++; - } - -$i=0; -$user_group_string='|'; -$user_group_ct = count($user_group); -while($i < $user_group_ct) - { - $user_group_string .= "$user_group[$i]|"; - $user_group_SQL .= "'$user_group[$i]',"; - $user_groupQS .= "&user_group[]=$user_group[$i]"; - $i++; - } -if ( (preg_match("/--ALL--/",$user_group_string) ) or ($user_group_ct < 1) ) - {$user_group_SQL = "";} -else - { - $user_group_SQL = preg_replace("/,\$/",'',$user_group_SQL); - $user_group_SQL_str=$user_group_SQL; - $user_group_SQL = "and log.user_group IN($user_group_SQL)"; - } - - - -$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; -$rslt=mysql_to_mysqli($stmt, $link); -if ($DB) {$HTML_text.="$stmt\n";} -$campaigns_to_print = mysqli_num_rows($rslt); -$i=0; -$groups=array(); -while ($i < $campaigns_to_print) - { - $row=mysqli_fetch_row($rslt); - $groups[$i] =$row[0]; - $i++; - } - -$i=0; -$group_string='|'; -$group_ct = count($group); -while($i < $group_ct) - { - if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) - { - $group_string .= "$group[$i]|"; - $group_SQL .= "'$group[$i]',"; - $groupQS .= "&group[]=$group[$i]"; - } - $i++; - } - -if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) - {$group_SQL = "";} -else - { - $group_SQL = preg_replace("/,\$/",'',$group_SQL); - $group_SQL_str=$group_SQL; - $group_SQL = "and campaign_id IN($group_SQL)"; - } - -$LINKbase = "$PHP_SELF?query_date=$query_date&end_date=$end_date&shift=$shift&DB=$DB&user=$user$groupQS&search_archived_data=$search_archived_data&report_display_type=$report_display_type"; - -# $NWB = "   \"HELP\""; - -$NWB = "\"HELP\""; - -if ($file_download < 1) - { - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo "\n"; - echo ""; - - echo "\n"; - echo "\n"; - echo "\n"; - - echo "\n"; - echo ""._QXZ("$report_name")."\n"; - echo ""; - - $short_header=1; - - require("admin_header.php"); - - echo "\n"; - echo "\n"; - echo ""._QXZ("$report_name")." $NWB#user_group_hourly_detail$NWE\n"; - echo "
";
-	}
-
-if ($SUBMIT && $query_date && $start_hour && $end_hour) {
-
-	$CSV_text .= "\""._QXZ("$report_name",24).":  $NOW_TIME ($db_source)\"\n\n";
-	$CSV_text .= "\""._QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\"\n";
-	$CSV_text .= "\""._QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\"\n";
-	$CSV_text .= "\""._QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\"\n\n";
-
-	$ASCII_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
-	$ASCII_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
-	$ASCII_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
-	$ASCII_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
-
-	$HTML_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
-	$HTML_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
-	$HTML_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
-	$HTML_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
-
-	$stmt="select distinct      log.user_group,       substr(log.event_time, 12, 2) AS hour,log.user user from ".$vicidial_agent_log_table." log join vicidial_users u using(user) where log.event_time>='$query_date $start_hour:00:00' and log.event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL";
-	if ($DB) {$ASCII_text.="* ".$stmt."\n";}
-	$rslt=mysql_to_mysqli($stmt, $link);
-
-	 
-	$UserGroups=array();
-	$hour_array=array();
-	$hour_total_array=array();
-	$tempIDPerusegroup=array();
-	$countByUserGroupByHour=array();
-	$countByUserGroup=array();
-	$countUserHour=array();
-	$cont=0;
-	$allData=array();
-	$temp[]=9;
-	$temp[]=7;
-	$temp[]=9;
-	while($row=mysqli_fetch_array($rslt)) {
-		#echo $row["user_group"]."-->".$row["user"]."
"; - $temp=array(); - $temp[]=$row["user_group"]; - - $temp[]=$row["hour"]; - $temp[]=$row["user"]; - $allData[$row["user_group"]][$row["hour"]][]=$row["user"]; - - $hour_array[]=$row["hour"]; - $UserGroups[]=$row["user_group"]; - $countByUserGroupByHour[$row["user_group"]][$row["hour"]]+=1; - $countByUserGroup[$row["user_group"]]+=1; - $countUserHour[$row["hour"]]+=1; - - - - } - $UserGroups=array_unique($UserGroups); - $hour_array=array_unique($hour_array); - - $total_stmt="select user_group, count(distinct user) as ct from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL group by user_group order by user_group,2"; - $total_rslt=mysql_to_mysqli($total_stmt, $link); - if ($DB) {$ASCII_text.="* ".$total_stmt."\n";} - $total_array=array(); - while ($total_row=mysqli_fetch_array($total_rslt)) { - $total_array[$total_row["user_group"]]+=$total_row["ct"]; - } - - $grand_total_stmt="select distinct user from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL"; - $grand_total_rslt=mysql_to_mysqli($grand_total_stmt, $link); - $grand_total=mysqli_num_rows($grand_total_rslt); - - $ASCII_header ="+----------------------+"; - $ASCII_title .="| "._QXZ("USER GROUP", 20)." |"; - $ASCII_total .="| "._QXZ("TOTALS", 6)." |"; - - $table_columns=1; - $HTML_text.=""; - $HTML_text.=""; - $HTML_text.=""; - - $HTML_text2.=""; - $HTML_text2.=""; - - $CSV_text.="\""._QXZ("USER GROUP")."\""; - $CSV_total.="\""._QXZ("TOTALS")."\""; - $maxUserByUserGroup=array(); - foreach($UserGroups as $Ugroup){ - - foreach($hour_array as $hour){ - //echo "group-->". $data[0]." hour-->".$data[1]." agent-->".$data[2]."
"; - $a=$allData[$Ugroup][$hour]; - if(isset($maxUserByUserGroup[$Ugroup])){ - if(count($a)>$maxUserByUserGroup[$Ugroup]){ - $maxUserByUserGroup[$Ugroup]=count($a); - - } - - }else{ - $maxUserByUserGroup[$Ugroup]=count($a); - - } - } - } - //print_r($hour_array); - foreach($hour_array as $key){ - - $ASCII_title.=" ".date("ha", strtotime("$key:00"))." to "; - $key1=$key+1; - $ASCII_title.=date("ha", strtotime("$key1:00"))." |"; - $ASCII_header.="--------------+"; - $ASCII_total.=" ".sprintf("%12s", ($countUserHour[$key]+0))." |"; - - $HTML_text.=""; - $HTML_text2.=""; - $table_columns++; - - $CSV_text.=",\"".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."\""; - $CSV_total.=",\"".($countUserHour[$key]+0)."\""; - } - if ($hour_array) {reset($hour_array);} - if ($user_group_array) {reset($user_group_array);} - - - $ASCII_text.=$ASCII_header."\n"; - $ASCII_text.=$ASCII_title."\n"; - $ASCII_text.=$ASCII_header."\n"; - - $HTML_text.="\n"; - - $CSV_text.="\n"; - - $prev_group=""; - $UG_ct=1; - foreach($UserGroups as $Ugroup){ - # echo "$Ugroup---->$hour--->".$maxUserByUserGroup[$Ugroup]."
"; - # echo "
$Ugroup
"; - foreach($hour_array as $hour){ - if($allData[$Ugroup][$hour]) {sort($allData[$Ugroup][$hour]);} - } - if ($hour_array) {reset($hour_array);} - - for($cont=0; $cont < $maxUserByUserGroup[$Ugroup] ;$cont ++){ - $ASCII_text.="| ".sprintf("%20s", $Ugroup)." |" ; - $HTML_text.=""; - $HTML_text.=""; - $CSV_text.="\"$Ugroup\""; - foreach($hour_array as $hour){ - $ASCII_text.=" ".sprintf("%12s", ($allData[$Ugroup][$hour][$cont]))." |"; - $HTML_text.=""; - $CSV_text.=",\"".($allData[$Ugroup][$hour][$cont])."\""; - } - - $CSV_text.="\n"; - $HTML_text.="\n"; - $ASCII_text.="\n"; - - } - - if ($prev_group!=$Ugroup) { - $ASCII_text.=$ASCII_header."\n"; - if ($UG_ct";} - $CSV_text.="\n"; - } - $prev_group=$Ugroup; - $UG_ct++; - } - - if ($hour_array) {reset($hour_array);} - $ASCII_text.=$ASCII_header."\n"; - $ASCII_text.=$ASCII_total."\n"; - $ASCII_text.=$ASCII_header."\n"; - - $HTML_text2.=""; - $HTML_text2.="
"._QXZ("USER GROUP")."
"._QXZ("TOTALS")."".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."".($countUserHour[$key]+0)."
".$Ugroup." ".($allData[$Ugroup][$hour][$cont])." 
 
"; - $HTML_text.=$HTML_text2; - - $CSV_text.=$CSV_total."\n"; - -} - - -if ($file_download > 0) - { - $US='_'; - $FILE_TIME = date("Ymd-His"); - $CSVfilename = "USER_GROUP_HOURLY_DETAIL_$US$FILE_TIME.csv"; - - // We'll be outputting a TXT file - header('Content-type: application/octet-stream'); - - // It will be called LIST_101_20090209-121212.txt - header("Content-Disposition: attachment; filename=\"$CSVfilename\""); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); - ob_clean(); - flush(); - - echo "$CSV_text"; - - if ($db_source == 'S') - { - mysqli_close($link); - $use_slave_server=0; - $db_source = 'M'; - require("dbconnect_mysqli.php"); - } - - $endMS = microtime(); - $startMSary = explode(" ",$startMS); - $endMSary = explode(" ",$endMS); - $runS = ($endMSary[0] - $startMSary[0]); - $runM = ($endMSary[1] - $startMSary[1]); - $TOTALrun = ($runS + $runM); - - $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; - if ($DB) {echo "|$stmt|\n";} - $rslt=mysql_to_mysqli($stmt, $link); - - exit; - } - - -echo "
"; -echo "\n"; - -echo ""; -echo ""; -echo "
"._QXZ("Date").":
"; -echo "\n"; -echo ""; -?> - - - - "._QXZ("Campaigns").":
"; -echo "\n"; - -echo "
"._QXZ("Teams/User Groups").":
"; -echo "\n"; -echo "
\n"; -#echo "Display as:
"; -#echo "\n

"; - -if ($archives_available=="Y") - { - echo ""._QXZ("Search archived data")."\n"; - } - -echo "

"._QXZ("Display as:")."
"; -echo "\n

"; - -echo "

\n"; -echo "
        "; - -echo "          \n"; -echo ""._QXZ("DOWNLOAD")." |"; -echo " "._QXZ("REPORTS")." | v1\n"; -echo "\n"; -echo "
"._QXZ("Start time").": :00:00"; - -echo "
"._QXZ("End time").": :59:59"; -echo "
"; - -echo "
"; - -if ($report_display_type=="HTML") - { -# echo $GRAPH_text; -# echo $JS_text; - echo $HTML_text; - } -else - { - echo $ASCII_text; - } - - -echo "\n"; -?> + +# Joseph Johnson +# Matt Florell +# +# Thanks to Joseph Johnson LICENSE: AGPLv2 +# I took his report as base for this one. +# +# Gives hourly detail of distinct agents per user group, with totals. +# For single days only +# +# CHANGES +# 170816-2012 - First build +# 170816-2152 - Added HTML option +# 170818-0749 - Added upgraded code, fixes and link to v1 of report +# 170829-0040 - Added screen color settings +# 180507-2315 - Added new help display +# 191013-0816 - Fixes for PHP7 +# + +$startMS = microtime(); + +require("dbconnect_mysqli.php"); +require("functions.php"); + +$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; +$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; +$PHP_SELF=$_SERVER['PHP_SELF']; +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["start_hour"])) {$start_hour=$_GET["start_hour"];} + elseif (isset($_POST["start_hour"])) {$start_hour=$_POST["start_hour"];} +if (isset($_GET["end_hour"])) {$end_hour=$_GET["end_hour"];} + elseif (isset($_POST["end_hour"])) {$end_hour=$_POST["end_hour"];} +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} + elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} +if (isset($_GET["user"])) {$user=$_GET["user"];} + elseif (isset($_POST["user"])) {$user=$_POST["user"];} +if (isset($_GET["shift"])) {$shift=$_GET["shift"];} + elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} +if (isset($_GET["stage"])) {$stage=$_GET["stage"];} + elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} +if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} + elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} +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 (strlen($shift)<2) {$shift='ALL';} + +$report_name = 'User Group Detail Hourly Report'; +$db_source = 'M'; + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,enable_languages,language_method,report_default_format FROM system_settings;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$qm_conf_ct = mysqli_num_rows($rslt); +if ($qm_conf_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $non_latin = $row[0]; + $outbound_autodial_active = $row[1]; + $slave_db_server = $row[2]; + $reports_use_slave_db = $row[3]; + $SSenable_languages = $row[4]; + $SSlanguage_method = $row[5]; + $SSreport_default_format = $row[6]; + } +##### END SETTINGS LOOKUP ##### + +########################################### +if (strlen($report_display_type)<2) {$report_display_type = $SSreport_default_format;} + +### ARCHIVED DATA CHECK CONFIGURATION +$archives_available="N"; +$log_tables_array=array("vicidial_agent_log"); +for ($t=0; $t 0) + { + $row=mysqli_fetch_row($rslt); + $VUselected_language = $row[0]; + } + +$auth=0; +$reports_auth=0; +$admin_auth=0; +$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'REPORTS',1,0); +if ($auth_message == 'GOOD') + {$auth=1;} + +if ($auth > 0) + { + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 7 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $admin_auth=$row[0]; + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports='1';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $row=mysqli_fetch_row($rslt); + $reports_auth=$row[0]; + + if ($reports_auth < 1) + { + $VDdisplayMESSAGE = _QXZ("You are not allowed to view reports"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + if ( ($reports_auth > 0) and ($admin_auth < 1) ) + { + $ADD=999999; + $reports_only_user=1; + } + } +else + { + $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); + if ($auth_message == 'LOCK') + { + $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); + Header ("Content-type: text/html; charset=utf-8"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; + exit; + } + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; + exit; + } + +##### BEGIN log visit to the vicidial_report_log table ##### +$LOGip = getenv("REMOTE_ADDR"); +$LOGbrowser = getenv("HTTP_USER_AGENT"); +$LOGscript_name = getenv("SCRIPT_NAME"); +$LOGserver_name = getenv("SERVER_NAME"); +$LOGserver_port = getenv("SERVER_PORT"); +$LOGrequest_uri = getenv("REQUEST_URI"); +$LOGhttp_referer = getenv("HTTP_REFERER"); +if (preg_match("/443/i",$LOGserver_port)) {$HTTPprotocol = 'https://';} + else {$HTTPprotocol = 'http://';} +if (($LOGserver_port == '80') or ($LOGserver_port == '443') ) {$LOGserver_port='';} +else {$LOGserver_port = ":$LOGserver_port";} +$LOGfull_url = "$HTTPprotocol$LOGserver_name$LOGserver_port$LOGrequest_uri"; + +$LOGhostname = php_uname('n'); +if (strlen($LOGhostname)<1) {$LOGhostname='X';} +if (strlen($LOGserver_name)<1) {$LOGserver_name='X';} + +$stmt="SELECT webserver_id FROM vicidial_webservers where webserver='$LOGserver_name' and hostname='$LOGhostname' LIMIT 1;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {echo "$stmt\n";} +$webserver_id_ct = mysqli_num_rows($rslt); +if ($webserver_id_ct > 0) + { + $row=mysqli_fetch_row($rslt); + $webserver_id = $row[0]; + } +else + { + ##### insert webserver entry + $stmt="INSERT INTO vicidial_webservers (webserver,hostname) values('$LOGserver_name','$LOGhostname');"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_to_mysqli($stmt, $link); + $affected_rows = mysqli_affected_rows($link); + $webserver_id = mysqli_insert_id($link); + } + +$stmt="INSERT INTO vicidial_report_log set event_date=NOW(), user='$PHP_AUTH_USER', ip_address='$LOGip', report_name='$report_name', browser='$LOGbrowser', referer='$LOGhttp_referer', notes='$LOGserver_name:$LOGserver_port $LOGscript_name |$group[0], $query_date, $end_date, $shift, $file_download, $report_display_type|', url='$LOGfull_url', webserver='$webserver_id';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$report_log_id = mysqli_insert_id($link); +##### END log visit to the vicidial_report_log table ##### + +if ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) + { + mysqli_close($link); + $use_slave_server=1; + $db_source = 'S'; + require("dbconnect_mysqli.php"); + echo "\n"; + } + +$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGuser_group = $row[0]; + +$stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';"; +if ($DB) {echo "|$stmt|\n";} +$rslt=mysql_to_mysqli($stmt, $link); +$row=mysqli_fetch_row($rslt); +$LOGallowed_campaigns = $row[0]; +$LOGallowed_reports = $row[1]; +$LOGadmin_viewable_groups = $row[2]; +$LOGadmin_viewable_call_times = $row[3]; + +if ( (!preg_match("/$report_name/",$LOGallowed_reports)) and (!preg_match("/ALL REPORTS/",$LOGallowed_reports)) ) + { + Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); + Header("HTTP/1.0 401 Unauthorized"); + echo _QXZ("You are not allowed to view this report").": |$PHP_AUTH_USER|$report_name|\n"; + exit; + } + +$LOGallowed_campaignsSQL=''; +$whereLOGallowed_campaignsSQL=''; +if ( (!preg_match('/\-ALL/i', $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')"; + } +$regexLOGallowed_campaigns = " $LOGallowed_campaigns "; + +$LOGadmin_viewable_groupsSQL=''; +$vuLOGadmin_viewable_groupsSQL=''; +$whereLOGadmin_viewable_groupsSQL=''; +if ( (!preg_match('/\-\-ALL\-\-/i',$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')"; + $vuLOGadmin_viewable_groupsSQL = "and vicidial_users.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; + } + +$LOGadmin_viewable_call_timesSQL=''; +$whereLOGadmin_viewable_call_timesSQL=''; +if ( (!preg_match('/\-\-ALL\-\-/i', $LOGadmin_viewable_call_times)) and (strlen($LOGadmin_viewable_call_times) > 3) ) + { + $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ -/",'',$LOGadmin_viewable_call_times); + $rawLOGadmin_viewable_call_timesSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_call_timesSQL); + $LOGadmin_viewable_call_timesSQL = "and call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; + $whereLOGadmin_viewable_call_timesSQL = "where call_time_id IN('---ALL---','$rawLOGadmin_viewable_call_timesSQL')"; + } + +$MT[0]=''; +$NOW_DATE = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$STARTtime = date("U"); +if (!isset($group)) {$group = array();} +if (!isset($user_group)) {$user_group = array();} +if (!isset($query_date)) {$query_date = $NOW_DATE;} +if (!isset($start_hour)) {$start_hour = date("H");} +if (!isset($end_hour)) {$end_hour = date("H");} + + +$stmt="select user_group from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$user_groups_to_print = mysqli_num_rows($rslt); +$i=0; +$user_groups=array(); +while ($i < $user_groups_to_print) + { + $row=mysqli_fetch_row($rslt); + $user_groups[$i] =$row[0]; + $i++; + } + +$i=0; +$user_group_string='|'; +$user_group_ct = count($user_group); +while($i < $user_group_ct) + { + $user_group_string .= "$user_group[$i]|"; + $user_group_SQL .= "'$user_group[$i]',"; + $user_groupQS .= "&user_group[]=$user_group[$i]"; + $i++; + } +if ( (preg_match("/--ALL--/",$user_group_string) ) or ($user_group_ct < 1) ) + {$user_group_SQL = "";} +else + { + $user_group_SQL = preg_replace("/,\$/",'',$user_group_SQL); + $user_group_SQL_str=$user_group_SQL; + $user_group_SQL = "and log.user_group IN($user_group_SQL)"; + } + + + +$stmt="SELECT campaign_id from vicidial_campaigns $whereLOGallowed_campaignsSQL order by campaign_id;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$HTML_text.="$stmt\n";} +$campaigns_to_print = mysqli_num_rows($rslt); +$i=0; +$groups=array(); +while ($i < $campaigns_to_print) + { + $row=mysqli_fetch_row($rslt); + $groups[$i] =$row[0]; + $i++; + } + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + if ( (preg_match("/ $group[$i] /",$regexLOGallowed_campaigns)) or (preg_match("/-ALL/",$LOGallowed_campaigns)) ) + { + $group_string .= "$group[$i]|"; + $group_SQL .= "'$group[$i]',"; + $groupQS .= "&group[]=$group[$i]"; + } + $i++; + } + +if ( (preg_match("/--ALL--/",$group_string) ) or ($group_ct < 1) ) + {$group_SQL = "";} +else + { + $group_SQL = preg_replace("/,\$/",'',$group_SQL); + $group_SQL_str=$group_SQL; + $group_SQL = "and campaign_id IN($group_SQL)"; + } + +$LINKbase = "$PHP_SELF?query_date=$query_date&end_date=$end_date&shift=$shift&DB=$DB&user=$user$groupQS&search_archived_data=$search_archived_data&report_display_type=$report_display_type"; + +# $NWB = "   \"HELP\""; + +$NWB = "\"HELP\""; + +if ($file_download < 1) + { + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo ""; + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo ""._QXZ("$report_name")."\n"; + echo ""; + + $short_header=1; + + require("admin_header.php"); + + echo "\n"; + echo "\n"; + echo ""._QXZ("$report_name")." $NWB#user_group_hourly_detail$NWE\n"; + echo "
";
+	}
+
+if ($SUBMIT && $query_date && $start_hour && $end_hour) {
+
+	$CSV_text .= "\""._QXZ("$report_name",24).":  $NOW_TIME ($db_source)\"\n\n";
+	$CSV_text .= "\""._QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\"\n";
+	$CSV_text .= "\""._QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\"\n";
+	$CSV_text .= "\""._QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\"\n\n";
+
+	$ASCII_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
+	$ASCII_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
+	$ASCII_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
+	$ASCII_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
+
+	$HTML_text .= _QXZ("$report_name",24).": $user                     $NOW_TIME ($db_source)\n\n";
+	$HTML_text .= _QXZ("Time range").": $query_date $start_hour:00:00 "._QXZ("to")." $query_date $end_hour:59:59\n";
+	$HTML_text .= _QXZ("User groups").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $user_group))."\n";
+	$HTML_text .= _QXZ("Campaigns").": ".preg_replace('/\-\-ALL\-\-/', "--"._QXZ("ALL")."--", implode(', ', $group))."\n\n";
+
+	$stmt="select distinct      log.user_group,       substr(log.event_time, 12, 2) AS hour,log.user user from ".$vicidial_agent_log_table." log join vicidial_users u using(user) where log.event_time>='$query_date $start_hour:00:00' and log.event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL";
+	if ($DB) {$ASCII_text.="* ".$stmt."\n";}
+	$rslt=mysql_to_mysqli($stmt, $link);
+
+	 
+	$UserGroups=array();
+	$hour_array=array();
+	$hour_total_array=array();
+	$tempIDPerusegroup=array();
+	$countByUserGroupByHour=array();
+	$countByUserGroup=array();
+	$countUserHour=array();
+	$cont=0;
+	$allData=array();
+	$temp[]=9;
+	$temp[]=7;
+	$temp[]=9;
+	while($row=mysqli_fetch_array($rslt)) {
+		#echo $row["user_group"]."-->".$row["user"]."
"; + $temp=array(); + $temp[]=$row["user_group"]; + + $temp[]=$row["hour"]; + $temp[]=$row["user"]; + $allData[$row["user_group"]][$row["hour"]][]=$row["user"]; + + $hour_array[]=$row["hour"]; + $UserGroups[]=$row["user_group"]; + $countByUserGroupByHour[$row["user_group"]][$row["hour"]]+=1; + $countByUserGroup[$row["user_group"]]+=1; + $countUserHour[$row["hour"]]+=1; + + + + } + $UserGroups=array_unique($UserGroups); + $hour_array=array_unique($hour_array); + + $total_stmt="select user_group, count(distinct user) as ct from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL group by user_group order by user_group,2"; + $total_rslt=mysql_to_mysqli($total_stmt, $link); + if ($DB) {$ASCII_text.="* ".$total_stmt."\n";} + $total_array=array(); + while ($total_row=mysqli_fetch_array($total_rslt)) { + $total_array[$total_row["user_group"]]+=$total_row["ct"]; + } + + $grand_total_stmt="select distinct user from ".$vicidial_agent_log_table." where event_time>='$query_date $start_hour:00:00' and event_time<='$query_date $end_hour:59:59' $group_SQL $user_group_SQL"; + $grand_total_rslt=mysql_to_mysqli($grand_total_stmt, $link); + $grand_total=mysqli_num_rows($grand_total_rslt); + + $ASCII_header ="+----------------------+"; + $ASCII_title .="| "._QXZ("USER GROUP", 20)." |"; + $ASCII_total .="| "._QXZ("TOTALS", 6)." |"; + + $table_columns=1; + $HTML_text.=""; + $HTML_text.=""; + $HTML_text.=""; + + $HTML_text2.=""; + $HTML_text2.=""; + + $CSV_text.="\""._QXZ("USER GROUP")."\""; + $CSV_total.="\""._QXZ("TOTALS")."\""; + $maxUserByUserGroup=array(); + foreach($UserGroups as $Ugroup){ + + foreach($hour_array as $hour){ + //echo "group-->". $data[0]." hour-->".$data[1]." agent-->".$data[2]."
"; + $a=$allData[$Ugroup][$hour]; + if(isset($maxUserByUserGroup[$Ugroup])){ + if(count($a)>$maxUserByUserGroup[$Ugroup]){ + $maxUserByUserGroup[$Ugroup]=count($a); + + } + + }else{ + $maxUserByUserGroup[$Ugroup]=count($a); + + } + } + } + //print_r($hour_array); + foreach($hour_array as $key){ + + $ASCII_title.=" ".date("ha", strtotime("$key:00"))." to "; + $key1=$key+1; + $ASCII_title.=date("ha", strtotime("$key1:00"))." |"; + $ASCII_header.="--------------+"; + $ASCII_total.=" ".sprintf("%12s", ($countUserHour[$key]+0))." |"; + + $HTML_text.=""; + $HTML_text2.=""; + $table_columns++; + + $CSV_text.=",\"".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."\""; + $CSV_total.=",\"".($countUserHour[$key]+0)."\""; + } + if ($hour_array) {reset($hour_array);} + if ($user_group_array) {reset($user_group_array);} + + + $ASCII_text.=$ASCII_header."\n"; + $ASCII_text.=$ASCII_title."\n"; + $ASCII_text.=$ASCII_header."\n"; + + $HTML_text.="\n"; + + $CSV_text.="\n"; + + $prev_group=""; + $UG_ct=1; + foreach($UserGroups as $Ugroup){ + # echo "$Ugroup---->$hour--->".$maxUserByUserGroup[$Ugroup]."
"; + # echo "
$Ugroup
"; + foreach($hour_array as $hour){ + if($allData[$Ugroup][$hour]) {sort($allData[$Ugroup][$hour]);} + } + if ($hour_array) {reset($hour_array);} + + for($cont=0; $cont < $maxUserByUserGroup[$Ugroup] ;$cont ++){ + $ASCII_text.="| ".sprintf("%20s", $Ugroup)." |" ; + $HTML_text.=""; + $HTML_text.=""; + $CSV_text.="\"$Ugroup\""; + foreach($hour_array as $hour){ + $ASCII_text.=" ".sprintf("%12s", ($allData[$Ugroup][$hour][$cont]))." |"; + $HTML_text.=""; + $CSV_text.=",\"".($allData[$Ugroup][$hour][$cont])."\""; + } + + $CSV_text.="\n"; + $HTML_text.="\n"; + $ASCII_text.="\n"; + + } + + if ($prev_group!=$Ugroup) { + $ASCII_text.=$ASCII_header."\n"; + if ($UG_ct";} + $CSV_text.="\n"; + } + $prev_group=$Ugroup; + $UG_ct++; + } + + if ($hour_array) {reset($hour_array);} + $ASCII_text.=$ASCII_header."\n"; + $ASCII_text.=$ASCII_total."\n"; + $ASCII_text.=$ASCII_header."\n"; + + $HTML_text2.=""; + $HTML_text2.="
"._QXZ("USER GROUP")."
"._QXZ("TOTALS")."".date("ha", strtotime("$key:00"))." to ".date("ha", strtotime("$key1:00"))."".($countUserHour[$key]+0)."
".$Ugroup." ".($allData[$Ugroup][$hour][$cont])." 
 
"; + $HTML_text.=$HTML_text2; + + $CSV_text.=$CSV_total."\n"; + +} + + +if ($file_download > 0) + { + $US='_'; + $FILE_TIME = date("Ymd-His"); + $CSVfilename = "USER_GROUP_HOURLY_DETAIL_$US$FILE_TIME.csv"; + + // We'll be outputting a TXT file + header('Content-type: application/octet-stream'); + + // It will be called LIST_101_20090209-121212.txt + header("Content-Disposition: attachment; filename=\"$CSVfilename\""); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + ob_clean(); + flush(); + + echo "$CSV_text"; + + if ($db_source == 'S') + { + mysqli_close($link); + $use_slave_server=0; + $db_source = 'M'; + require("dbconnect_mysqli.php"); + } + + $endMS = microtime(); + $startMSary = explode(" ",$startMS); + $endMSary = explode(" ",$endMS); + $runS = ($endMSary[0] - $startMSary[0]); + $runM = ($endMSary[1] - $startMSary[1]); + $TOTALrun = ($runS + $runM); + + $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; + if ($DB) {echo "|$stmt|\n";} + $rslt=mysql_to_mysqli($stmt, $link); + + exit; + } + + +echo "
"; +echo "\n"; + +echo ""; +echo ""; +echo "
"._QXZ("Date").":
"; +echo "\n"; +echo ""; +?> + + + + "._QXZ("Campaigns").":
"; +echo "\n"; + +echo "
"._QXZ("Teams/User Groups").":
"; +echo "\n"; +echo "
\n"; +#echo "Display as:
"; +#echo "\n

"; + +if ($archives_available=="Y") + { + echo ""._QXZ("Search archived data")."\n"; + } + +echo "

"._QXZ("Display as:")."
"; +echo "\n

"; + +echo "

\n"; +echo "
        "; + +echo "          \n"; +echo ""._QXZ("DOWNLOAD")." |"; +echo " "._QXZ("REPORTS")." | v1\n"; +echo "\n"; +echo "
"._QXZ("Start time").": :00:00"; + +echo "
"._QXZ("End time").": :59:59"; +echo "
"; + +echo "
"; + +if ($report_display_type=="HTML") + { +# echo $GRAPH_text; +# echo $JS_text; + echo $HTML_text; + } +else + { + echo $ASCII_text; + } + + +echo "\n"; +?> diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index 24f486dd..135bab79 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -2567,6 +2567,8 @@ if (isset($_GET["no_agent_delay"])) {$no_agent_delay=$_GET["no_agent_delay"]; elseif (isset($_POST["no_agent_delay"])) {$no_agent_delay=$_POST["no_agent_delay"];} if (isset($_GET["hopper_drop_run_trigger"])) {$hopper_drop_run_trigger=$_GET["hopper_drop_run_trigger"];} elseif (isset($_POST["hopper_drop_run_trigger"])) {$hopper_drop_run_trigger=$_POST["hopper_drop_run_trigger"];} +if (isset($_GET["hopper_drop_run_trigger_all"])) {$hopper_drop_run_trigger_all=$_GET["hopper_drop_run_trigger_all"];} + elseif (isset($_POST["hopper_drop_run_trigger_all"])) {$hopper_drop_run_trigger_all=$_POST["hopper_drop_run_trigger_all"];} if (isset($_GET["daily_call_count_limit"])) {$daily_call_count_limit=$_GET["daily_call_count_limit"];} elseif (isset($_POST["daily_call_count_limit"])) {$daily_call_count_limit=$_POST["daily_call_count_limit"];} if (isset($_GET["daily_limit_manual"])) {$daily_limit_manual=$_GET["daily_limit_manual"];} @@ -3262,6 +3264,8 @@ $agent_hidden_sound = preg_replace('/[^-_0-9a-zA-Z]/','',$agent_hidden_sound); $leave_3way_start_recording = preg_replace('/[^-_0-9a-zA-Z]/','',$leave_3way_start_recording); $leave_3way_start_recording_exception = preg_replace('/[^-_0-9a-zA-Z]/','',$leave_3way_start_recording_exception); $agent_screen_timer = preg_replace('/[^-_0-9a-zA-Z]/','',$agent_screen_timer); +$hopper_drop_run_trigger = preg_replace('/[^0-9a-zA-Z]/','',$hopper_drop_run_trigger); +$hopper_drop_run_trigger_all = preg_replace('/[^0-9a-zA-Z]/','',$hopper_drop_run_trigger_all); if ($non_latin < 1) { @@ -3357,7 +3361,6 @@ if ($non_latin < 1) $mute_recordings = preg_replace('/[^0-9a-zA-Z]/','',$mute_recordings); $leave_vm_no_dispo = preg_replace('/[^0-9a-zA-Z]/','',$leave_vm_no_dispo); $amd_agent_route_options = preg_replace('/[^0-9a-zA-Z]/','',$amd_agent_route_options); - $hopper_drop_run_trigger = preg_replace('/[^0-9a-zA-Z]/','',$hopper_drop_run_trigger); ### ALPHA-NUMERIC and spaces and hash and star and comma $xferconf_a_dtmf = preg_replace('/[^ \,\*\#0-9a-zA-Z]/','',trim($xferconf_a_dtmf)); @@ -4045,7 +4048,6 @@ else $mute_recordings = preg_replace('/[^0-9\p{L}]/u','',$mute_recordings); $leave_vm_no_dispo = preg_replace('/[^0-9\p{L}]/u','',$leave_vm_no_dispo); $amd_agent_route_options = preg_replace('/[^0-9\p{L}]/u','',$amd_agent_route_options); - $hopper_drop_run_trigger = preg_replace('/[^0-9\p{L}]/u','',$hopper_drop_run_trigger); ### ALPHA-NUMERIC and spaces and hash and star and comma $xferconf_a_dtmf = preg_replace('/[^ \,\*\#0-9\p{L}]/u','',trim($xferconf_a_dtmf)); @@ -5564,12 +5566,13 @@ if ($SSscript_remove_js > 0) # 210321-0120 - Added classAudioFile PHP library # 210324-0954 - Added leave_3way_start_recording campaign options # 210325-2220 - Added populate_lead_comments in-group option +# 210406-1821 - Added hopper_drop_run_trigger_all option, moved dialable_leads function to functions.php # # 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-807a'; -$build = '210325-2220'; +$admin_version = '2.14-808a'; +$build = '210406-1821'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); @@ -7369,13 +7372,14 @@ if ($ADD==73) ### call function to calculate and print dialable leads $single_status=0; - dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL); + $only_return=0; + dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,$fSQL,$only_return); echo "

\n"; echo ""._QXZ("Without Filter").":\n"; echo "

\n"; - dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,''); + dialable_leads($DB,$link,$local_call_time,$dial_statuses,$camp_lists,$drop_lockout_time,$call_count_limit,$single_status,'',$only_return); echo "

\n"; echo "\n"; @@ -16314,9 +16318,14 @@ if ($ADD==41) $hdrtSQL=''; $hdrtMESSAGE=''; if ($hopper_drop_run_trigger == 'Y') { - $hdrtSQL = ",hopper_drop_run_trigger='$hopper_drop_run_trigger'"; + $hdrtSQL = ",hopper_drop_run_trigger='Y'"; $hdrtMESSAGE='Hopper Drop-Run Triggered'; } + if ($hopper_drop_run_trigger_all == 'A') + { + $hdrtSQL = ",hopper_drop_run_trigger='A'"; + $hdrtMESSAGE='Hopper All-Drops-Run Triggered'; + } $stmtA="UPDATE vicidial_campaigns set campaign_name='$campaign_name',active='$active',dial_status_a='$dial_status_a',dial_status_b='$dial_status_b',dial_status_c='$dial_status_c',dial_status_d='$dial_status_d',dial_status_e='$dial_status_e',lead_order='$lead_order',allow_closers='$allow_closers',hopper_level='$hopper_level', auto_trim_hopper='$auto_trim_hopper', use_auto_hopper='$use_auto_hopper', auto_hopper_multi='$auto_hopper_multi', $adlSQL next_agent_call='$next_agent_call', local_call_time='$local_call_time', voicemail_ext='$voicemail_ext', dial_timeout='$dial_timeout', dial_prefix='$dial_prefix', campaign_cid='$campaign_cid', campaign_vdad_exten='$campaign_vdad_exten', web_form_address='" . mysqli_real_escape_string($link, $web_form_address) . "', park_ext='$park_ext', park_file_name='$park_file_name', campaign_rec_exten='$campaign_rec_exten', campaign_recording='$campaign_recording', campaign_rec_filename='$campaign_rec_filename', campaign_script='$script_id', get_call_launch='$get_call_launch', am_message_exten='$am_message_exten', amd_send_to_vmx='$amd_send_to_vmx', xferconf_a_dtmf='$xferconf_a_dtmf',xferconf_a_number='$xferconf_a_number',xferconf_b_dtmf='$xferconf_b_dtmf',xferconf_b_number='$xferconf_b_number',lead_filter_id='$lead_filter_id',alt_number_dialing='$alt_number_dialing',scheduled_callbacks='$scheduled_callbacks',drop_action='$drop_action',drop_call_seconds='$drop_call_seconds',safe_harbor_exten='$safe_harbor_exten',wrapup_seconds='$wrapup_seconds',wrapup_message='$wrapup_message',closer_campaigns=$closer_campaignsSQL,use_internal_dnc='$use_internal_dnc',allcalls_delay='$allcalls_delay',omit_phone_code='$omit_phone_code',dial_method='$dial_method',available_only_ratio_tally='$available_only_ratio_tally',adaptive_dropped_percentage='$adaptive_dropped_percentage',adaptive_maximum_level='$adaptive_maximum_level',adaptive_latest_server_time='$adaptive_latest_server_time',adaptive_intensity='$adaptive_intensity',adaptive_dl_diff_target='$adaptive_dl_diff_target',concurrent_transfers='$concurrent_transfers',auto_alt_dial='$auto_alt_dial',agent_pause_codes_active='$agent_pause_codes_active',campaign_description='$campaign_description',campaign_changedate='$SQLdate',campaign_stats_refresh='$campaign_stats_refresh',disable_alter_custdata='$disable_alter_custdata',no_hopper_leads_logins='$no_hopper_leads_logins',list_order_mix='$list_order_mix',campaign_allow_inbound='$campaign_allow_inbound',manual_dial_list_id='$manual_dial_list_id',default_xfer_group='$default_xfer_group',xfer_groups='$XFERgroups_value',queue_priority='$queue_priority',drop_inbound_group='$drop_inbound_group',disable_alter_custphone='$disable_alter_custphone',display_queue_count='$display_queue_count',manual_dial_filter='$manual_dial_filter',agent_clipboard_copy='$agent_clipboard_copy',agent_extended_alt_dial='$agent_extended_alt_dial',use_campaign_dnc='$use_campaign_dnc',three_way_call_cid='$three_way_call_cid',three_way_dial_prefix='$three_way_dial_prefix',web_form_target='$web_form_target',vtiger_search_category='$vtiger_search_category',vtiger_create_call_record='$vtiger_create_call_record',vtiger_create_lead_record='$vtiger_create_lead_record',vtiger_screen_login='$vtiger_screen_login',cpd_amd_action='$cpd_amd_action',agent_allow_group_alias='$agent_allow_group_alias',default_group_alias='$default_group_alias',vtiger_search_dead='$vtiger_search_dead',vtiger_status_call='$vtiger_status_call',drop_lockout_time='$drop_lockout_time',quick_transfer_button='$quick_transfer_button',prepopulate_transfer_preset='$prepopulate_transfer_preset',drop_rate_group='$drop_rate_group',view_calls_in_queue='$view_calls_in_queue',view_calls_in_queue_launch='$view_calls_in_queue_launch',grab_calls_in_queue='$grab_calls_in_queue',call_requeue_button='$call_requeue_button',pause_after_each_call='$pause_after_each_call',no_hopper_dialing='$no_hopper_dialing',agent_dial_owner_only='$agent_dial_owner_only',agent_display_dialable_leads='$agent_display_dialable_leads',web_form_address_two='" . mysqli_real_escape_string($link, $web_form_address_two) . "',waitforsilence_options='$waitforsilence_options',agent_select_territories='$agent_select_territories',crm_popup_login='$crm_popup_login',crm_login_address='" . mysqli_real_escape_string($link, $crm_login_address) . "',timer_action='$timer_action',timer_action_message='$timer_action_message',timer_action_seconds='$timer_action_seconds',start_call_url='" . mysqli_real_escape_string($link, $start_call_url) . "',dispo_call_url='" . mysqli_real_escape_string($link, $dispo_call_url) . "',xferconf_c_number='$xferconf_c_number',xferconf_d_number='$xferconf_d_number',xferconf_e_number='$xferconf_e_number',use_custom_cid='$use_custom_cid',scheduled_callbacks_alert='$scheduled_callbacks_alert',queuemetrics_callstatus_override='$queuemetrics_callstatus',extension_appended_cidname='$extension_appended_cidname',scheduled_callbacks_count='$scheduled_callbacks_count',manual_dial_override='$manual_dial_override',blind_monitor_warning='$blind_monitor_warning',blind_monitor_message='" . mysqli_real_escape_string($link, $blind_monitor_message) . "',blind_monitor_filename='$blind_monitor_filename',inbound_queue_no_dial='$inbound_queue_no_dial',timer_action_destination='$timer_action_destination',enable_xfer_presets='$enable_xfer_presets',hide_xfer_number_to_dial='$hide_xfer_number_to_dial',manual_dial_prefix='$manual_dial_prefix',customer_3way_hangup_logging='$customer_3way_hangup_logging',customer_3way_hangup_seconds='$customer_3way_hangup_seconds',customer_3way_hangup_action='$customer_3way_hangup_action',ivr_park_call='$ivr_park_call',ivr_park_call_agi='$ivr_park_call_agi',manual_preview_dial='$manual_preview_dial',realtime_agent_time_stats='$realtime_agent_time_stats',api_manual_dial='$api_manual_dial',manual_dial_call_time_check='$manual_dial_call_time_check',lead_order_randomize='$lead_order_randomize',lead_order_secondary='$lead_order_secondary',per_call_notes='$per_call_notes',my_callback_option='$my_callback_option',agent_lead_search='$agent_lead_search',agent_lead_search_method='$agent_lead_search_method',queuemetrics_phone_environment='$queuemetrics_phone_environment',auto_pause_precall='$auto_pause_precall',auto_resume_precall='$auto_resume_precall',auto_pause_precall_code='$auto_pause_precall_code',manual_dial_cid='$manual_dial_cid',post_phone_time_diff_alert='$post_phone_time_diff_alert',custom_3way_button_transfer='$custom_3way_button_transfer',available_only_tally_threshold='$available_only_tally_threshold',available_only_tally_threshold_agents='$available_only_tally_threshold_agents',dial_level_threshold='$dial_level_threshold',dial_level_threshold_agents='$dial_level_threshold_agents',safe_harbor_audio='$safe_harbor_audio',safe_harbor_menu_id='$safe_harbor_menu_id',callback_days_limit='$callback_days_limit',dl_diff_target_method='$dl_diff_target_method',disable_dispo_screen='$disable_dispo_screen',disable_dispo_status='$disable_dispo_status',screen_labels='$screen_labels',status_display_fields='$status_display_fields',na_call_url='" . mysqli_real_escape_string($link, $na_call_url) . "',pllb_grouping='$pllb_grouping',pllb_grouping_limit='$pllb_grouping_limit',call_count_limit='$call_count_limit',call_count_target='$call_count_target',callback_hours_block='$callback_hours_block',callback_list_calltime='$callback_list_calltime',user_group='$user_group',hopper_vlc_dup_check='$hopper_vlc_dup_check',in_group_dial='$in_group_dial',in_group_dial_select='$in_group_dial_select',safe_harbor_audio_field='$safe_harbor_audio_field',pause_after_next_call='$pause_after_next_call',owner_populate='$owner_populate',use_other_campaign_dnc='$use_other_campaign_dnc',allow_emails='$allow_emails',allow_chats='$allow_chats',amd_inbound_group='$amd_inbound_group',amd_callmenu='$amd_callmenu',manual_dial_lead_id='$manual_dial_lead_id',dead_max='$dead_max',dispo_max='$dispo_max',pause_max='$pause_max',dead_max_dispo='$dead_max_dispo',dispo_max_dispo='$dispo_max_dispo',max_inbound_calls='$max_inbound_calls',manual_dial_search_checkbox='$manual_dial_search_checkbox',hide_call_log_info='$hide_call_log_info',timer_alt_seconds='$timer_alt_seconds',wrapup_bypass='$wrapup_bypass',wrapup_after_hotkey='$wrapup_after_hotkey',callback_active_limit='$callback_active_limit',callback_active_limit_override='$callback_active_limit_override',comments_all_tabs='$comments_all_tabs',comments_dispo_screen='$comments_dispo_screen',comments_callback_screen='$comments_callback_screen',qc_comment_history='$qc_comment_history',show_previous_callback='$show_previous_callback',clear_script='$clear_script',cpd_unknown_action='$cpd_unknown_action',manual_dial_search_filter='$manual_dial_search_filter',web_form_address_three='" . mysqli_real_escape_string($link, $web_form_address_three) . "',manual_dial_override_field='$manual_dial_override_field',status_display_ingroup='$status_display_ingroup',customer_gone_seconds='$customer_gone_seconds',agent_display_fields='$agent_display_fields',am_message_wildcards='$am_message_wildcards',manual_dial_timeout='$manual_dial_timeout',routing_initiated_recordings='$routing_initiated_recordings',manual_dial_hopper_check='$manual_dial_hopper_check',callback_useronly_move_minutes='$callback_useronly_move_minutes',ofcom_uk_drop_calc='$ofcom_uk_drop_calc',manual_auto_next='$manual_auto_next',manual_auto_show='$manual_auto_show',allow_required_fields='$allow_required_fields',dead_to_dispo='$dead_to_dispo',agent_xfer_validation='$agent_xfer_validation',ready_max_logout='$ready_max_logout',callback_display_days='$callback_display_days',three_way_record_stop='$three_way_record_stop',hangup_xfer_record_start='$hangup_xfer_record_start',scheduled_callbacks_email_alert='$scheduled_callbacks_email_alert',max_inbound_calls_outcome='$max_inbound_calls_outcome',manual_auto_next_options='$manual_auto_next_options',agent_screen_time_display='$agent_screen_time_display',next_dial_my_callbacks='$next_dial_my_callbacks',inbound_no_agents_no_dial_container='$inbound_no_agents_no_dial_container',inbound_no_agents_no_dial_threshold='$inbound_no_agents_no_dial_threshold',cid_group_id='$cid_group_id',pause_max_dispo='$pause_max_dispo',script_top_dispo='$script_top_dispo',dead_trigger_seconds='$dead_trigger_seconds',dead_trigger_action='$dead_trigger_action',dead_trigger_repeat='$dead_trigger_repeat',dead_trigger_filename='$dead_trigger_filename',dead_trigger_url='" . mysqli_real_escape_string($link, $dead_trigger_url) . "',scheduled_callbacks_force_dial='$scheduled_callbacks_force_dial',scheduled_callbacks_auto_reschedule='$scheduled_callbacks_auto_reschedule',scheduled_callbacks_timezones_container='$scheduled_callbacks_timezones_container',three_way_volume_buttons='$three_way_volume_buttons',callback_dnc='$callback_dnc',manual_dial_validation='$manual_dial_validation',mute_recordings='$mute_recordings',auto_active_list_new='$auto_active_list_new',call_quota_lead_ranking='$call_quota_lead_ranking',sip_event_logging='$sip_event_logging',campaign_script_two='$campaign_script_two',leave_vm_no_dispo='$leave_vm_no_dispo',leave_vm_message_group_id='$leave_vm_message_group_id',dial_timeout_lead_container='$dial_timeout_lead_container',amd_type='$amd_type',vmm_daily_limit='$vmm_daily_limit',opensips_cid_name='$opensips_cid_name',amd_agent_route_options='$amd_agent_route_options',browser_alert_sound='$browser_alert_sound',browser_alert_volume='$browser_alert_volume',three_way_record_stop_exception='$three_way_record_stop_exception',pause_max_exceptions='$pause_max_exceptions',daily_call_count_limit='$daily_call_count_limit',daily_limit_manual='$daily_limit_manual',transfer_button_launch='$transfer_button_launch',shared_dial_rank='$shared_dial_rank',agent_search_method='$agent_search_method',clear_form='$clear_form',leave_3way_start_recording='$leave_3way_start_recording',leave_3way_start_recording_exception='$leave_3way_start_recording_exception'$hdrtSQL where campaign_id='$campaign_id';"; if ($DB) {echo "|$stmt|\n";} @@ -16338,9 +16347,16 @@ if ($ADD==41) $rslt=mysql_to_mysqli($stmt, $link); } - if ($hopper_drop_run_trigger == 'Y') + if ($hopper_drop_run_trigger_all == 'A') { - echo "
"._QXZ("Hopper Drop-Run Triggered")."\n"; + echo "
"._QXZ("Hopper All-Drops-Run Triggered")."\n"; + } + else + { + if ($hopper_drop_run_trigger == 'Y') + { + echo "
"._QXZ("Hopper Drop-Run Triggered")."\n"; + } } ### LOG INSERTION Admin Log Table ### @@ -25432,7 +25448,7 @@ if ($ADD==31) { echo "
"._QXZ("Hopper Drop-Run Trigger").": $NWB#campaigns-hopper_drop_run_trigger$NWE
"._QXZ("Hopper Drop-Run Trigger").":   "._QXZ("All Drops").": $NWB#campaigns-hopper_drop_run_trigger$NWE
"._QXZ("Drop Lockout Time").": $NWB#campaigns-drop_lockout_time$NWE