LICENSE: AGPLv2 # # CHANGES # # 80502-0857 - First build # 80506-0228 - Added user field to search by # 90508-0644 - Changed to PHP long tags # 130414-0235 - Added report logging # 130610-0942 - Finalized changing of all ereg instances to preg # 130616-2045 - Added filtering of input to prevent SQL injection attacks and new user auth # 130901-0817 - Changed to mysqli PHP functions # 140108-0721 - Added webserver and hostname to report logging # 141114-0031 - Finalized adding QXZ translation to all admin files # 141230-0950 - Added code for on-the-fly language translations display # 170409-1534 - Added IP List validation code # 220227-1936 - Added allow_web_debug system setting # 220812-0935 - Added User Group report permissions checking # 240801-1130 - Code updates for PHP8 compatibility # $startMS = microtime(); $report_name='SPH Report'; require("dbconnect_mysqli.php"); require("functions.php"); ##### Pull values from posted form variables ##### $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; $PHP_SELF=$_SERVER['PHP_SELF']; $PHP_SELF = preg_replace('/\.php.*/i','.php',$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["end_date"])) {$end_date=$_GET["end_date"];} elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];} elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];} 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["shift"])) {$shift=$_GET["shift"];} elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} if (isset($_GET["role"])) {$role=$_GET["role"];} elseif (isset($_POST["role"])) {$role=$_POST["role"];} if (isset($_GET["order"])) {$order=$_GET["order"];} elseif (isset($_POST["order"])) {$order=$_POST["order"];} if (isset($_GET["user"])) {$user=$_GET["user"];} elseif (isset($_POST["user"])) {$user=$_POST["user"];} 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"];} $NOW_DATE = date("Y-m-d"); $NOW_TIME = date("Y-m-d H:i:s"); $STARTtime = date("U"); if (!isset($query_date)) {$query_date = $NOW_DATE;} if (!isset($end_date)) {$end_date = $NOW_DATE;} if (!is_array($campaign)) {$campaign = array();} if (!is_array($group)) {$group = array();} if (!is_array($user_group)) {$group = array();} if (strlen($shift)<2) {$shift='ALL';} if (strlen($role)<2) {$role='ALL';} if (strlen($order)<2) {$order='sales_down';} $DB=preg_replace("/[^0-9a-zA-Z]/","",$DB); ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### $stmt = "SELECT use_non_latin,enable_languages,language_method,allow_web_debug 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]; $SSenable_languages = $row[1]; $SSlanguage_method = $row[2]; $SSallow_web_debug = $row[3]; } if ($SSallow_web_debug < 1) {$DB=0;} ##### END SETTINGS LOOKUP ##### ########################################### $query_date = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$query_date); $end_date = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$end_date); $shift = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$shift); $role = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$role); $order = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$order); $user = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$user); $submit = preg_replace('/[^-_0-9a-zA-Z]/',"",$submit); $SUBMIT = preg_replace('/[^-_0-9a-zA-Z]/',"",$SUBMIT); # Variables filtered further down in the code # $campaign # $user_group # $group 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_USER = preg_replace('/[^-_0-9\p{L}]/u', '', $PHP_AUTH_USER); $PHP_AUTH_PW = preg_replace('/[^-_0-9\p{L}]/u', '', $PHP_AUTH_PW); } $stmt="SELECT selected_language,user_group 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]; $LOGuser_group = $row[1]; } $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 allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times 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]; $LOGadmin_viewable_groups = $row[2]; $LOGadmin_viewable_call_times = $row[3]; $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 "; 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 "You are not allowed to view this report: |$PHP_AUTH_USER|$report_name|\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|', 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 ##### $campaign_ct = count($campaign); $group_ct = count($group); $user_group_ct = count($user_group); $stmt="select campaign_id from vicidial_campaigns;"; $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {echo "$stmt\n";} $campaigns_to_print = mysqli_num_rows($rslt); $i=0; $LISTcampaigns[$i]='---NONE---'; $i++; $campaigns_to_print++; while ($i < $campaigns_to_print) { $row=mysqli_fetch_row($rslt); $LISTcampaigns[$i] =$row[0]; $i++; } $stmt="select group_id from vicidial_inbound_groups;"; $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {echo "$stmt\n";} $groups_to_print = mysqli_num_rows($rslt); $i=0; $LISTgroups[$i]='---NONE---'; $i++; $groups_to_print++; while ($i < $groups_to_print) { $row=mysqli_fetch_row($rslt); $LISTgroups[$i] =$row[0]; $i++; } $stmt="select user_group from vicidial_user_groups;"; $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {echo "$stmt\n";} $user_groups_to_print = mysqli_num_rows($rslt); $i=0; $LISTuser_groups[$i]='---ALL---'; $i++; $user_groups_to_print++; while ($i < $user_groups_to_print) { $row=mysqli_fetch_row($rslt); $LISTuser_groups[$i] =$row[0]; $i++; } ##### START HTML ##### ?>
\n";
if ($group_ct < 1)
{
echo "\n";
echo _QXZ("PLEASE SELECT AN IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT")."\n";
echo " "._QXZ("NOTE: stats taken from shift specified")."\n";
}
else
{
/*
if ($shift == 'AM')
{
$time_BEGIN=$AM_shift_BEGIN;
$time_END=$AM_shift_END;
if (strlen($time_BEGIN) < 6) {$time_BEGIN = "03:45:00";}
if (strlen($time_END) < 6) {$time_END = "15:14:59";}
}
if ($shift == 'PM')
{
$time_BEGIN=$PM_shift_BEGIN;
$time_END=$PM_shift_END;
if (strlen($time_BEGIN) < 6) {$time_BEGIN = "15:15:00";}
if (strlen($time_END) < 6) {$time_END = "23:15:00";}
}
if ($shift == 'ALL')
{
if (strlen($time_BEGIN) < 6) {$time_BEGIN = "00:00:00";}
if (strlen($time_END) < 6) {$time_END = "23:59:59";}
}
$query_date_BEGIN = "$query_date $time_BEGIN";
$query_date_END = "$end_date $time_END";
if (strlen($user_group)>0) {$ugSQL="and vicidial_agent_log.user_group='$user_group'";}
else {$ugSQL='';}
*/
echo _QXZ("VICIDIAL: Agent SPH Report",50)." $NOW_TIME\n";
echo _QXZ("Time range").": $query_date "._QXZ("to")." $end_date\n\n";
echo "---------- "._QXZ("AGENTS SPH DETAILS")." -------------\n\n";
echo "| # | \n"; echo ""._QXZ("USER")." | \n"; echo ""._QXZ("NAME")." | \n"; echo ""._QXZ("ROLE")." | \n"; echo ""._QXZ("GROUP")." | \n"; echo ""._QXZ("CALLS")." | \n"; echo ""._QXZ("HOURS")." | \n"; echo ""._QXZ("SALES")." | \n"; echo ""._QXZ("SPH")." | \n"; echo "
| $j | \n"; echo "$user_id[$i] | \n"; echo "$full_name[$i] | \n"; echo "$roleX[$i] | \n"; echo "$group[$i] | \n"; echo "$calls[$i] | \n"; echo "$hours[$i] | \n"; echo "$sales[$i] | \n"; echo "$sph[$i] | \n"; echo "
| "._QXZ("TOTALS")." | \n"; echo "$TOTcalls | \n"; echo "$TOThours | \n"; echo "$TOTsales | \n"; echo "$TOTsph | \n"; echo "||||