Files
agc_2-X/www/vicidial/NANPA_running_processes.php
T
2013-09-22 18:07:49 +00:00

171 lines
6.5 KiB
PHP

<?php
# NANPA_running_processes.php
#
# Copyright (C) 2013 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
#
# This script shows running NANPA filter batch proccesses
#
# CHANGELOG:
# 130921-0756 - First build of script
#
$version = '2.8-1';
$build = '130921-0756';
$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["output_codes_to_display"])) {$output_codes_to_display=$_GET["output_codes_to_display"];}
elseif (isset($_POST["output_codes_to_display"])) {$output_codes_to_display=$_POST["output_codes_to_display"];}
#############################################
##### START SYSTEM_SETTINGS LOOKUP #####
$stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db 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];
}
##### 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);
}
$NOW_DATE = date("Y-m-d");
$user_auth=0;
$auth=0;
$reports_auth=0;
$qc_auth=0;
$auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'QC',1);
if ($auth_message == 'GOOD')
{$user_auth=1;}
if ($user_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);
$auth=$row[0];
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 6 and view_reports > 0;";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$reports_auth=$row[0];
$stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and user_level > 1 and qc_enabled > 0;";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);
$row=mysqli_fetch_row($rslt);
$qc_auth=$row[0];
$reports_only_user=0;
$qc_only_user=0;
if ( ($reports_auth > 0) and ($auth < 1) )
{
$ADD=999999;
$reports_only_user=1;
}
if ( ($qc_auth > 0) and ($reports_auth < 1) and ($auth < 1) )
{
if ( ($ADD != '881') and ($ADD != '100000000000000') )
{
$ADD=100000000000000;
}
$qc_only_user=1;
}
if ( ($qc_auth < 1) and ($reports_auth < 1) and ($auth < 1) )
{
$VDdisplayMESSAGE = "You do not have permission to be here";
Header ("Content-type: text/html; charset=utf-8");
echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n";
exit;
}
}
else
{
$VDdisplayMESSAGE = "Login incorrect, please try again";
if ($auth_message == 'LOCK')
{
$VDdisplayMESSAGE = "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;
}
$oc_ct=count($output_codes_to_display);
$oc_SQL="";
$url_str="";
for ($i=0; $i<$oc_ct; $i++) {
$oc_SQL.="'$output_codes_to_display[$i]',";
$url_str.="output_codes_to_display[]=".$output_codes_to_display[$i];
}
$oc_SQL=substr($oc_SQL, 0, -1);
$process_stmt="select * from vicidial_nanpa_filter_log where output_code in ($oc_SQL) and status!='COMPLETED'";
$process_rslt=mysqli_query($link, $process_stmt);
if (mysqli_num_rows($process_rslt)>0) {
# echo "<html>";
# echo "<head>";
# echo "<title>NANPA running processes</title>";
# echo "</head>";
# echo "<body marginheight=0 marginwidth=0 leftmargin=0 topmargin=0>";
echo "<table width='770' cellpadding=5 cellspacing=0>";
echo "<tr><th colspan='7' bgcolor='#015B91'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Currently running NANPA scrubs</th></tr>";
echo "<tr>";
echo "<td align='left' bgcolor='#015B91' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Start time</th>";
echo "<td align='left' bgcolor='#015B91' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Status</th>";
echo "<td align='left' bgcolor='#015B91' width='100'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Last updated</th>";
echo "<td align='left' bgcolor='#015B91' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Leads count</th>";
echo "<td align='left' bgcolor='#015B91' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Filter count</th>";
echo "<td align='left' bgcolor='#015B91' width='180'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Status line</th>";
echo "<td align='left' bgcolor='#015B91' width='170'><FONT FACE=\"ARIAL,HELVETICA\" COLOR=WHITE SIZE=2>Last script output</th>";
echo "</tr>";
while ($row=mysqli_fetch_array($process_rslt)) {
if ($bgcolor=="#9BB9FB") {$bgcolor="#B9CBFD";} else {$bgcolor='#9BB9FB';}
$row["script_output"]=preg_replace('/\n/', '<BR/>', $row["script_output"]);
echo "<tr>";
echo "<td align='left' bgcolor='$bgcolor' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR='#000000' size='1'>$row[start_time]</th>";
echo "<td align='left' bgcolor='$bgcolor' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR='#000000' size='1'>$row[status]</th>";
echo "<td align='left' bgcolor='$bgcolor' width='100'><FONT FACE=\"ARIAL,HELVETICA\" COLOR='#000000' size='1'>$row[update_time]</th>";
echo "<td align='left' bgcolor='$bgcolor' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR='#000000' size='1'>$row[leads_count]</th>";
echo "<td align='left' bgcolor='$bgcolor' width='80'><FONT FACE=\"ARIAL,HELVETICA\" COLOR='#000000' size='1'>$row[filter_count]</th>";
echo "<td align='left' bgcolor='$bgcolor' width='180'><FONT FACE=\"ARIAL,HELVETICA\" COLOR='#000000' size='1'>$row[status_line]</th>";
echo "<td align='left' bgcolor='$bgcolor' width='170'><FONT FACE=\"ARIAL,HELVETICA\" COLOR='#000000' size='1'>$row[script_output]</th>";
echo "</tr>";
}
echo "</table>";
# echo "</body>";
# echo "</html>";
}
?>