From 4b13bf13e964816de385334c03e8a98db0e419a1 Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 29 Aug 2017 01:09:07 +0000 Subject: [PATCH] Added Inbound DID Summary Report git-svn-id: svn://192.168.202.10@2811 3d104415-ff17-0410-8863-d5cf3c621b8a --- UPGRADE | 2 + www/vicidial/AST_DIDstats_v2.php | 826 +++++++++++++++++++++++++++++++ www/vicidial/admin.php | 13 +- 3 files changed, 836 insertions(+), 5 deletions(-) create mode 100644 www/vicidial/AST_DIDstats_v2.php diff --git a/UPGRADE b/UPGRADE index 94fd1fad..76159913 100644 --- a/UPGRADE +++ b/UPGRADE @@ -190,6 +190,8 @@ OTHER CHANGES: active lists. Also changed Advanced Lead Management tool to allow you to select multiple lists. +45. Added Inbound DID Summary Report + diff --git a/www/vicidial/AST_DIDstats_v2.php b/www/vicidial/AST_DIDstats_v2.php new file mode 100644 index 00000000..583403fa --- /dev/null +++ b/www/vicidial/AST_DIDstats_v2.php @@ -0,0 +1,826 @@ + LICENSE: AGPLv2 +# +# CHANGES +# +# 170828-2018 - First build, based on AST_DIDstats.php +# + +$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["group"])) {$group=$_GET["group"];} + elseif (isset($_POST["group"])) {$group=$_POST["group"];} +if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} + elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} +if (isset($_GET["time_BEGIN"])) {$time_BEGIN=$_GET["time_BEGIN"];} + elseif (isset($_POST["time_BEGIN"])) {$time_BEGIN=$_POST["time_BEGIN"];} +if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} + elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} +if (isset($_GET["time_END"])) {$time_END=$_GET["time_END"];} + elseif (isset($_POST["time_END"])) {$time_END=$_POST["time_END"];} +if (isset($_GET["shift"])) {$shift=$_GET["shift"];} + elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} +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["file_download"])) {$file_download=$_GET["file_download"];} + elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} +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"];} + +if (strlen($shift)<2) {$shift='--';} + +$report_name = 'Inbound DID Summary 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) {$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]; + $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"; +$table_name="vicidial_did_log"; +$archive_table_name=use_archive_table($table_name); +if ($archive_table_name!=$table_name) {$archives_available="Y";} + +if ($search_archived_data) + { + $vicidial_did_log_table=use_archive_table("vicidial_did_log"); + } +else + { + $vicidial_did_log_table="vicidial_did_log"; + } +############# + +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; + } + + +$stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER';"; +if ($DB) {$MAIN.="|$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) {$MAIN.="|$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; + } + +$LOGadmin_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')"; + } + +$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')"; + } + +$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($query_date)) {$query_date = $NOW_DATE;} +if (!isset($end_date)) {$end_date = $NOW_DATE;} +if (!isset($time_BEGIN)) {$time_BEGIN = "00:00:00";} +if (!isset($time_END)) {$time_END = "23:59:59";} + +$stmt="select did_id,did_pattern,did_description from vicidial_inbound_dids $whereLOGadmin_viewable_groupsSQL order by did_pattern;"; +$rslt=mysql_to_mysqli($stmt, $link); +if ($DB) {$MAIN.="$stmt\n";} +$groups_to_print = mysqli_num_rows($rslt); +$groups_string='|'; +$i=0; +while ($i < $groups_to_print) + { + $row=mysqli_fetch_row($rslt); + $groups[$i] = $row[0]; + $group_patterns[$i] = $row[1]; + $group_names[$i] = $row[2]; + $groups_string .= "$groups[$i]|"; + $i++; + } + +$i=0; +$group_string='|'; +$group_ct = count($group); +while($i < $group_ct) + { + if ( (strlen($group[$i]) > 0) and (preg_match("/\|$group[$i]\|/",$groups_string)) ) + { + $group_string .= "$group[$i]|"; + $group_SQL .= "'$group[$i]',"; + $groupQS .= "&group[]=$group[$i]"; + } + $i++; + } +if ( (preg_match('/\s\-\-NONE\-\-\s/',$group_string) ) or ($group_ct < 1) ) + { + $group_SQL = "''"; +# $group_SQL = "group_id IN('')"; + } +else + { + $group_SQL = preg_replace('/,$/i', '',$group_SQL); +# $group_SQL = "group_id IN($group_SQL)"; + } +if (strlen($group_SQL)<3) {$group_SQL="''";} + + +##### 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); + } + +$AMP='&'; +$QM='?'; +$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."?DB=".$DB."&file_download=".$file_download."&query_date=".$query_date."&end_date=".$end_date."&shift=".$shift."&report_display_type=".$report_display_type."$groupQS', 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 ##### + +##### BEGIN Define colors and logo ##### +$SSmenu_background='015B91'; +$SSframe_background='D9E6FE'; +$SSstd_row1_background='9BB9FB'; +$SSstd_row2_background='B9CBFD'; +$SSstd_row3_background='8EBCFD'; +$SSstd_row4_background='B6D3FC'; +$SSstd_row5_background='FFFFFF'; +$SSalt_row1_background='BDFFBD'; +$SSalt_row2_background='99FF99'; +$SSalt_row3_background='CCFFCC'; + +$screen_color_stmt="select admin_screen_colors from system_settings"; +$screen_color_rslt=mysql_to_mysqli($screen_color_stmt, $link); +$screen_color_row=mysqli_fetch_row($screen_color_rslt); +$agent_screen_colors="$screen_color_row[0]"; + +if ($agent_screen_colors != 'default') + { + $asc_stmt = "SELECT menu_background,frame_background,std_row1_background,std_row2_background,std_row3_background,std_row4_background,std_row5_background,alt_row1_background,alt_row2_background,alt_row3_background,web_logo FROM vicidial_screen_colors where colors_id='$agent_screen_colors';"; + $asc_rslt=mysql_to_mysqli($asc_stmt, $link); + $qm_conf_ct = mysqli_num_rows($asc_rslt); + if ($qm_conf_ct > 0) + { + $asc_row=mysqli_fetch_row($asc_rslt); + $SSmenu_background = $asc_row[0]; + $SSframe_background = $asc_row[1]; + $SSstd_row1_background = $asc_row[2]; + $SSstd_row2_background = $asc_row[3]; + $SSstd_row3_background = $asc_row[4]; + $SSstd_row4_background = $asc_row[5]; + $SSstd_row5_background = $asc_row[6]; + $SSalt_row1_background = $asc_row[7]; + $SSalt_row2_background = $asc_row[8]; + $SSalt_row3_background = $asc_row[9]; + $SSweb_logo = $asc_row[10]; + } + } + +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"; + } + +$NWB = "   \"HELP\""; + +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; + +$HEADER.="\n"; +$HEADER.="\n"; +$HEADER.="\n"; +require("chart_button.php"); +$HEADER.="\n"; +$HEADER.="\n"; + +$HEADER.="\n"; +$HEADER.=""._QXZ("$report_name")."\n"; + +$short_header=1; + +if ($DB > 0) + { + $MAIN.="
\n"; + $MAIN.="$group_ct|$group_string|$group_SQL\n"; + $MAIN.="
\n"; + $MAIN.="$shift|$query_date|$end_date\n"; + $MAIN.="
\n"; + } + +$MAIN.=""._QXZ("$report_name")." $NWB#DIDstats$NWE\n"; +$MAIN.="
"; + +$MAIN.="
\n"; +$MAIN.=""; +$MAIN.="
\n"; +$MAIN.=""; + +$MAIN.="\n"; +$MAIN.="
"; + + +$MAIN.="
"._QXZ("to")."

"; + +$MAIN.="\n"; +$MAIN.="
"; + +$MAIN.="
\n"; +$MAIN.="\n"; +$MAIN.="\n"; +$MAIN.="\n"; +$MAIN.=_QXZ("Display as:")."
"; +$MAIN.="\n

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

\n"; + } +$MAIN.="\n"; +$MAIN.="           "._QXZ("DOWNLOAD")." | "._QXZ("MODIFY")." | "._QXZ("REPORTS")." \n"; +$MAIN.="
\n"; +$MAIN.="
\n"; + +$MAIN.="
";
+
+$JS_text="