LICENSE: AGPLv2
#
# CHANGES
#
# 151023-0106 - First build
# 170409-1542 - Added IP List validation code
# 170822-2313 - Added screen colors
# 170823-1411 - Fixed delete bug
# 170829-0040 - Added screen color settings
# 171002-2140 - Added capability to add/modify preset variables
# 180508-2215 - Added new help display
# 220221-1926 - Added allow_web_debug system setting
#
$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'];
$PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF);
if (isset($_GET["DB"])) {$DB=$_GET["DB"];}
elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];}
if (isset($_GET["report_name"])) {$report_name=$_GET["report_name"];}
elseif (isset($_POST["report_name"])) {$report_name=$_POST["report_name"];}
if (isset($_GET["domain"])) {$domain=$_GET["domain"];}
elseif (isset($_POST["domain"])) {$domain=$_POST["domain"];}
if (isset($_GET["path_name"])) {$path_name=$_GET["path_name"];}
elseif (isset($_POST["path_name"])) {$path_name=$_POST["path_name"];}
if (isset($_GET["presets_string"])) {$presets_string=$_GET["presets_string"];}
elseif (isset($_POST["presets_string"])) {$presets_string=$_POST["presets_string"];}
if (isset($_GET["slave"])) {$slave=$_GET["slave"];}
elseif (isset($_POST["slave"])) {$slave=$_POST["slave"];}
if (isset($_GET["custom_reports_user_groups"])) {$custom_reports_user_groups=$_GET["custom_reports_user_groups"];}
elseif (isset($_POST["custom_reports_user_groups"])) {$custom_reports_user_groups=$_POST["custom_reports_user_groups"];}
if (isset($_GET["add_custom_report"])) {$add_custom_report=$_GET["add_custom_report"];}
elseif (isset($_POST["add_custom_report"])) {$add_custom_report=$_POST["add_custom_report"];}
if (isset($_GET["delete_custom_report"])) {$delete_custom_report=$_GET["delete_custom_report"];}
elseif (isset($_POST["delete_custom_report"])) {$delete_custom_report=$_POST["delete_custom_report"];}
if (isset($_GET["update_custom_report"])) {$update_custom_report=$_GET["update_custom_report"];}
elseif (isset($_POST["update_custom_report"])) {$update_custom_report=$_POST["update_custom_report"];}
if (isset($_GET["upd_custom_report_id"])) {$upd_custom_report_id=$_GET["upd_custom_report_id"];}
elseif (isset($_POST["upd_custom_report_id"])) {$upd_custom_report_id=$_POST["upd_custom_report_id"];}
if (isset($_GET["upd_report_name"])) {$upd_report_name=$_GET["upd_report_name"];}
elseif (isset($_POST["upd_report_name"])) {$upd_report_name=$_POST["upd_report_name"];}
if (isset($_GET["upd_path_name"])) {$upd_path_name=$_GET["upd_path_name"];}
elseif (isset($_POST["upd_path_name"])) {$upd_path_name=$_POST["upd_path_name"];}
if (isset($_GET["upd_presets_string"])) {$upd_presets_string=$_GET["upd_presets_string"];}
elseif (isset($_POST["upd_presets_string"])) {$upd_presets_string=$_POST["upd_presets_string"];}
if (isset($_GET["upd_slave"])) {$upd_slave=$_GET["upd_slave"];}
elseif (isset($_POST["upd_slave"])) {$upd_slave=$_POST["upd_slave"];}
if (isset($_GET["upd_domain"])) {$upd_domain=$_GET["upd_domain"];}
elseif (isset($_POST["upd_domain"])) {$upd_domain=$_POST["upd_domain"];}
if (isset($_GET["upd_custom_reports_user_groups"])) {$upd_custom_reports_user_groups=$_GET["upd_custom_reports_user_groups"];}
elseif (isset($_POST["upd_custom_reports_user_groups"])) {$upd_custom_reports_user_groups=$_POST["upd_custom_reports_user_groups"];}
$DB=preg_replace("/[^0-9a-zA-Z]/","",$DB);
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db,custom_fields_enabled,enable_languages,language_method,active_modules,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];
$outbound_autodial_active = $row[1];
$slave_db_server = $row[2];
$reports_use_slave_db = $row[3];
$custom_fields_enabled = $row[4];
$SSenable_languages = $row[5];
$SSlanguage_method = $row[6];
$active_modules = $row[7];
$SSallow_web_debug = $row[8];
}
if ($SSallow_web_debug < 1) {$DB=0;}
##### END SETTINGS LOOKUP #####
###########################################
$report_name = preg_replace('/[^- \,\|\_0-9a-zA-Z]/', '', $report_name);
$upd_report_name = preg_replace('/[^- \,\|\_0-9a-zA-Z]/', '', $upd_report_name);
$domain = preg_replace('/[^-\:\.\/\_0-9a-zA-Z]/', '', $domain);
$upd_domain = preg_replace('/[^-\:\.\/\_0-9a-zA-Z]/', '', $upd_domain);
$path_name = preg_replace('/[^-\[\]\:\.\/\_0-9a-zA-Z]/', '', $path_name);
$upd_path_name = preg_replace('/[^-\[\]\:\.\/\_0-9a-zA-Z]/', '', $upd_path_name);
$presets_string = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$presets_string);
$upd_presets_string = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$upd_presets_string);
$slave = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$slave);
$upd_slave = preg_replace("/\<|\>|\'|\"|\\\\|;/","",$upd_slave);
$add_custom_report = preg_replace('/[^- \,\|\_0-9a-zA-Z]/', '', $add_custom_report);
$delete_custom_report = preg_replace('/[^- \,\|\_0-9a-zA-Z]/', '', $delete_custom_report);
$update_custom_report = preg_replace('/[^- \,\|\_0-9a-zA-Z]/', '', $update_custom_report);
$upd_custom_report_id = preg_replace('/[^- \,\|\_0-9a-zA-Z]/', '', $upd_custom_report_id);
$upd_report_name = preg_replace('/[^- \,\|\_0-9a-zA-Z]/', '', $upd_report_name);
# Variables filtered further down in the code
# $custom_reports_user_groups
# $upd_custom_reports_user_groups
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 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') or ($auth_message == '2FA') )
{
$auth=1;
if ($auth_message == '2FA')
{
header ("Content-type: text/html; charset=utf-8");
echo _QXZ("Your session is expired").". "._QXZ("Click here to log in").".\n";
exit;
}
}
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 export_reports,user_group,admin_hide_lead_data,admin_hide_phone_data,admin_cf_show_hidden from vicidial_users where user='$PHP_AUTH_USER';";
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$LOGexport_reports = $row[0];
$LOGuser_group = $row[1];
$LOGadmin_hide_lead_data = $row[2];
$LOGadmin_hide_phone_data = $row[3];
$LOGadmin_cf_show_hidden = $row[4];
$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];
$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')";
$allowedUGarray=explode(" ", $rawLOGadmin_viewable_groupsSQL);
if (in_array('---ALL---',$custom_reports_user_groups))
{
$custom_reports_user_groups=$allowedUGarray;
}
}
# Need to do this just in case
if (preg_match('/\-\-ALL\-\-/i',$LOGadmin_viewable_groups)) {
$all_user_groups_stmt="select user_group from vicidial_user_groups";
$all_user_groups_rslt=mysql_to_mysqli($all_user_groups_stmt, $link);
$allowedUGarray=array();
while ($user_group_row=mysqli_fetch_row($all_user_groups_rslt))
{
array_push($allowedUGarray, $user_group_row[0]);
}
if (is_array($custom_reports_user_groups))
{
if (in_array('---ALL---',$custom_reports_user_groups))
{
$custom_reports_user_groups=$allowedUGarray;
}
}
}
# From system settings
$Vreports = array("Real-Time Main Report", " Real-Time Campaign Summary", " Inbound Report", " Inbound Service Level Report", " Inbound Summary Hourly Report", " Inbound Daily Report", " Inbound DID Report", " Inbound IVR Report", " Outbound Calling Report", " Outbound Summary Interval Report", " Outbound IVR Report", " Fronter - Closer Report", " Lists Campaign Statuses Report", " Campaign Status List Report", " Export Calls Report", " Export Leads Report", " Agent Time Detail", " Agent Status Detail", " Agent Performance Detail", " Team Performance Detail", " Performance Comparison Report", " Single Agent Daily", " Single Agent Daily Time", " User Group Login Report", " User Timeclock Report", " User Group Timeclock Status Report", " User Timeclock Detail Report", " Server Performance Report", " Administration Change Log", " List Update Stats", " User Stats", " User Time Sheet", " Download List", " Dialer Inventory Report", " Maximum System Stats", " Maximum Stats Detail", " Search Leads Logs", " Email Log Report", " Carrier Log Report", " Campaign Debug", " Hangup Cause Report", " Lists Pass Report", " Called Counts List IDs Report");
if ($add_custom_report) {
if (!$report_name || !$path_name) {
$error_msg="
"._QXZ("CANNOT ADD REPORT, SOME FIELDS ARE MISSING")."
";
} else {
if (in_array($report_name, $Vreports)) {
$error_msg="
"._QXZ("CANNOT ADD REPORT, REPORT NAME ALREADY IN USE FOR STANDARD VICIDIAL REPORT")."
";
} else {
$ins_stmt="insert into vicidial_custom_reports(report_name, date_added, user, domain, path_name, custom_variables) VALUES('$report_name', now(), '$PHP_AUTH_USER', '$domain', '$path_name', '$presets_string')";
$ins_rslt=mysql_to_mysqli($ins_stmt, $link);
if (mysqli_affected_rows($link)<1) {
$error_msg="
"._QXZ("INSERT FAILED")."
";
} else {
$temp_custom_reports_user_groups = implode("','", $custom_reports_user_groups);
$temp_custom_reports_user_groups = preg_replace("/\<|\>|\'|\"|\\\\|;/",'',$temp_custom_reports_user_groups);
$user_group_stmt="select user_group, allowed_custom_reports from vicidial_user_groups where user_group in ('".$temp_custom_reports_user_groups."') $LOGadmin_viewable_groupsSQL";
# echo $user_group_stmt."
\n";
$user_group_rslt=mysql_to_mysqli($user_group_stmt, $link);
while ($user_group_row=mysqli_fetch_array($user_group_rslt)) {
$user_group=$user_group_row["user_group"];
$allowed_custom_reports=$user_group_row["allowed_custom_reports"];
if (!preg_match('/^$report_name\||\|$report_name\|/i', $allowed_custom_reports)) {
$allowed_custom_reports=$allowed_custom_reports."$report_name|";
$upd_stmt="update vicidial_user_groups set allowed_custom_reports='$allowed_custom_reports' where user_group='$user_group'";
# echo $upd_stmt."
\n";
$upd_rslt=mysql_to_mysqli($upd_stmt, $link);
}
}
}
}
}
} else if ($upd_custom_report_id) {
if (preg_match('/\-\-ALL\-\-/i',$upd_custom_reports_user_groups)) {
$update_UG_array=$allowedUGarray; # All allowed user groups for user
} else {
$update_UG_array=explode("|", $upd_custom_reports_user_groups);
}
if (!$upd_report_name || !$upd_path_name) {
$error_msg="
"._QXZ("CANNOT UPDATE REPORT, SOME FIELDS ARE MISSING")."
";
} else {
if (in_array($upd_report_name, $Vreports)) {
$error_msg="
"._QXZ("CANNOT UPDATE REPORT, NEW CUSTOM REPORT NAME ALREADY IN USE FOR STANDARD VICIDIAL REPORT")."
";
} else {
$old_rpt_stmt="select report_name from vicidial_custom_reports from vicidial_custom_reports where custom_report_id='$upd_custom_report_id'";
$old_rpt_rslt=mysql_to_mysqli($old_rpt_stmt, $link);
$old_rpt_row=mysqli_fetch_row($old_rpt_rslt);
$old_rpt_name=$old_rpt_row[0];
$upd_stmt="update vicidial_custom_reports set report_name='$upd_report_name', date_added=now(), user='$PHP_AUTH_USER', domain='$upd_domain', path_name='$upd_path_name', custom_variables='$upd_presets_string' where custom_report_id='$upd_custom_report_id'";
$upd_rslt=mysql_to_mysqli($upd_stmt, $link);
if (mysqli_affected_rows($link)<1) {
$error_msg="
"._QXZ("UPDATE FAILED")."
";
} else {
$user_group_stmt="select user_group, allowed_custom_reports from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL";
$user_group_rslt=mysql_to_mysqli($user_group_stmt, $link);
while ($user_group_row=mysqli_fetch_array($user_group_rslt)) {
$user_group=$user_group_row["user_group"];
$allowed_custom_reports=$user_group_row["allowed_custom_reports"];
if (in_array($user_group, $update_UG_array)) {
if (!preg_match("/^$upd_report_name\||\|$upd_report_name\|/i", $allowed_custom_reports)) {
$allowed_custom_reports=$allowed_custom_reports."$upd_report_name|";
$upd_stmt="update vicidial_user_groups set allowed_custom_reports='$allowed_custom_reports' where user_group='$user_group'";
$upd_rslt=mysql_to_mysqli($upd_stmt, $link);
}
} else {
if (preg_match("/^$upd_report_name\||\|$upd_report_name\|/i", $allowed_custom_reports)) {
$allowed_custom_reports=preg_replace("/^$upd_report_name\||\|$upd_report_name\|/i", '', $allowed_custom_reports);
$upd_stmt="update vicidial_user_groups set allowed_custom_reports='$allowed_custom_reports' where user_group='$user_group'";
$upd_rslt=mysql_to_mysqli($upd_stmt, $link);
}
}
}
}
}
}
} else if ($delete_custom_report) {
$old_rpt_stmt="select report_name from vicidial_custom_reports from vicidial_custom_reports where custom_report_id='$upd_custom_report_id'";
$old_rpt_rslt=mysql_to_mysqli($old_rpt_stmt, $link);
$old_rpt_row=mysqli_fetch_row($old_rpt_rslt);
$old_rpt_name=$old_rpt_row[0];
$del_stmt="delete from vicidial_custom_reports where custom_report_id='$delete_custom_report'";
$del_rslt=mysql_to_mysqli($del_stmt, $link);
if (mysqli_affected_rows($link)<1) {
$error_msg="
"._QXZ("DELETE FAILED")."
";
} else {
$user_group_stmt="select user_group, allowed_custom_reports from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL";
$user_group_rslt=mysql_to_mysqli($user_group_stmt, $link);
while ($user_group_row=mysqli_fetch_array($user_group_rslt)) {
$user_group=$user_group_row["user_group"];
$allowed_custom_reports=$user_group_row["allowed_custom_reports"];
$old_report_removed=preg_replace("/^$old_rpt_name\||\|$old_rpt_name\|/i", "", $allowed_custom_reports);
$upd_stmt="update vicidial_user_groups set allowed_custom_reports='$old_report_removed' where user_group='$user_group'";
# echo $upd_stmt." - $allowed_custom_reports
\n";
$upd_rslt=mysql_to_mysqli($upd_stmt, $link);
}
}
}
require("screen_colors.php");
# $NWB = "
";
$NWB = "
";
echo "
| \n";
echo "";
echo "$error_msg";
echo " "; echo " "; $rpt_stmt="select * from vicidial_custom_reports"; $rpt_rslt=mysql_to_mysqli($rpt_stmt, $link); echo ""; echo " |