LICENSE: AGPLv2 # # CHANGES # # 90801-0910 - First build # 90809-0216 - Added Exclude Outbound Drop Group option # 100214-1421 - Sort menu alphabetically # 100216-0042 - Added popup date selector # 100712-1324 - Added system setting slave server option # 100802-2347 - Added User Group Allowed Reports option validation # 100914-1326 - Added lookup for user_level 7 users to set to reports only which will remove other admin links # 110703-1806 - Added download option # 111103-2315 - Added user_group restrictions for selecting in-groups # 120224-0910 - Added HTML display option with bar graphs # require("dbconnect.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["print_calls"])) {$print_calls=$_GET["print_calls"];} elseif (isset($_POST["print_calls"])) {$print_calls=$_POST["print_calls"];} if (isset($_GET["exclude_rollover"])) {$exclude_rollover=$_GET["exclude_rollover"];} elseif (isset($_POST["exclude_rollover"])) {$exclude_rollover=$_POST["exclude_rollover"];} if (isset($_GET["inbound_rate"])) {$inbound_rate=$_GET["inbound_rate"];} elseif (isset($_POST["inbound_rate"])) {$inbound_rate=$_POST["inbound_rate"];} if (isset($_GET["outbound_rate"])) {$outbound_rate=$_GET["outbound_rate"];} elseif (isset($_POST["outbound_rate"])) {$outbound_rate=$_POST["outbound_rate"];} if (isset($_GET["bareformat"])) {$bareformat=$_GET["bareformat"];} elseif (isset($_POST["bareformat"])) {$bareformat=$_POST["bareformat"];} if (isset($_GET["costformat"])) {$costformat=$_GET["costformat"];} elseif (isset($_POST["costformat"])) {$costformat=$_POST["costformat"];} 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["end_date"])) {$end_date=$_GET["end_date"];} elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} 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"];} $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); $MT[0]='0'; if (strlen($shift)<2) {$shift='ALL';} if (strlen($exclude_rollover)<2) {$exclude_rollover='NO';} $report_name = 'Inbound Summary Hourly Report'; $db_source = 'M'; ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### $stmt = "SELECT use_non_latin,outbound_autodial_active,slave_db_server,reports_use_slave_db FROM system_settings;"; $rslt=mysql_query($stmt, $link); if ($DB) {$MAIN.="$stmt\n";} $qm_conf_ct = mysql_num_rows($rslt); if ($qm_conf_ct > 0) { $row=mysql_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 ( (strlen($slave_db_server)>5) and (preg_match("/$report_name/",$reports_use_slave_db)) ) { mysql_close($link); $use_slave_server=1; $db_source = 'S'; require("dbconnect.php"); $MAIN.="\n"; } $stmt = "SELECT local_gmt FROM servers where active='Y' limit 1;"; $rslt=mysql_query($stmt, $link); if ($DB) {$MAIN.="$stmt\n";} $gmt_conf_ct = mysql_num_rows($rslt); $dst = date("I"); if ($gmt_conf_ct > 0) { $row=mysql_fetch_row($rslt); $local_gmt = $row[0]; $epoch_offset = (($local_gmt + $dst) * 3600); } $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level >= 7 and view_reports='1' and active='Y';"; if ($DB) {$MAIN.="|$stmt|\n";} if ($non_latin > 0) {$rslt=mysql_query("SET NAMES 'UTF8'");} $rslt=mysql_query($stmt, $link); $row=mysql_fetch_row($rslt); $auth=$row[0]; $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level='7' and view_reports='1' and active='Y';"; if ($DB) {$MAIN.="|$stmt|\n";} $rslt=mysql_query($stmt, $link); $row=mysql_fetch_row($rslt); $reports_only_user=$row[0]; if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth)) { Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\""); Header("HTTP/1.0 401 Unauthorized"); echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n"; exit; } $stmt="SELECT user_group from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 6 and view_reports='1' and active='Y';"; if ($DB) {$MAIN.="|$stmt|\n";} $rslt=mysql_query($stmt, $link); $row=mysql_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_query($stmt, $link); $row=mysql_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=\"VICI-PROJECTS\""); Header("HTTP/1.0 401 Unauthorized"); echo "You are not allowed to view this report: |$PHP_AUTH_USER|$report_name|\n"; exit; } $LOGadmin_viewable_groupsSQL=''; $whereLOGadmin_viewable_groupsSQL=''; if ( (!eregi("--ALL--",$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 ( (!eregi("--ALL--",$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 = '';} if (!isset($query_date)) {$query_date = $NOW_DATE;} if (!isset($end_date)) {$end_date = $NOW_DATE;} $exclude_rolloverSQL="$whereLOGadmin_viewable_groupsSQL"; if (eregi("YES",$exclude_rollover)) {$exclude_rolloverSQL = " where group_id NOT IN(SELECT drop_inbound_group from vicidial_campaigns) $LOGadmin_viewable_groupsSQL";} $stmt="select group_id,group_name from vicidial_inbound_groups $exclude_rolloverSQL order by group_id;"; $rslt=mysql_query($stmt, $link); if ($DB) {$MAIN.="$stmt\n";} $groups_to_print = mysql_num_rows($rslt); $i=0; $groups_string='|'; #$LISTgroups[$i]='---NONE---'; #$i++; #$groups_to_print++; while ($i < $groups_to_print) { $row=mysql_fetch_row($rslt); $LISTgroups[$i] = $row[0]; $LISTgroup_names[$i] = $row[1]; $groups_string .= "$LISTgroups[$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 ( (ereg("--NONE--",$group_string) ) or ($group_ct < 1) ) { $group_SQL = "''"; # $group_SQL = "group_id IN('')"; } else { $group_SQL = eregi_replace(",$",'',$group_SQL); # $group_SQL = "group_id IN($group_SQL)"; } if (strlen($group_SQL)<3) {$group_SQL="''";} $stmt="select vsc_id,vsc_name from vicidial_status_categories;"; $rslt=mysql_query($stmt, $link); if ($DB) {$MAIN.="$stmt\n";} $statcats_to_print = mysql_num_rows($rslt); $i=0; while ($i < $statcats_to_print) { $row=mysql_fetch_row($rslt); $vsc_id[$i] = $row[0]; $vsc_name[$i] = $row[1]; $vsc_count[$i] = 0; $i++; } $stmt="select call_time_id,call_time_name from vicidial_call_times $whereLOGadmin_viewable_call_timesSQL order by call_time_id;"; $rslt=mysql_query($stmt, $link); if ($DB) {$MAIN.="$stmt\n";} $times_to_print = mysql_num_rows($rslt); $i=0; while ($i < $times_to_print) { $row=mysql_fetch_row($rslt); $call_times[$i] = $row[0]; $call_time_names[$i] = $row[1]; $i++; } $HEADER.="\n"; $HEADER.="\n"; $HEADER.="\n"; $HEADER.="\n"; $HEADER.="\n"; $HEADER.="\n"; $HEADER.="\n"; $HEADER.="$report_name\n"; if ($bareformat < 1) { $short_header=1; # require("admin_header.php"); $MAIN.="
"; 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.="
\n"; $MAIN.="\n"; $MAIN.="
\n"; $MAIN.="\n"; $MAIN.="\n"; $MAIN.="\n"; $MAIN.="\n"; $MAIN.="\n"; $MAIN.="Date Range:
\n"; $MAIN.=""; $MAIN.=" \n"; $MAIN.=" to "; $MAIN.=" \n"; $MAIN.="
  \n"; $MAIN.="\n"; $MAIN.="Inbound Groups:
\n"; $MAIN.="\n"; $MAIN.="
\n"; $MAIN.="           "; $MAIN.="DOWNLOAD | "; $MAIN.="MODIFY | "; $MAIN.="REPORTS"; $MAIN.="\n"; $MAIN.="
  Display as: "; $MAIN.="\n
"; $MAIN.="   Exclude Outbound Drop Groups:
"; $MAIN.="   \n"; $MAIN.="
                      "; $MAIN.="\n"; $MAIN.="
\n"; $MAIN.="Call Time:
\n"; $MAIN.="\n"; $MAIN.="
\n"; $MAIN.="
\n"; $MAIN.="
\n\n"; $MAIN.="
\n\n";
	}

if ($groups_to_print < 1)
	{
	$MAIN.="\n\n";
	$MAIN.="PLEASE SELECT AN IN-GROUP AND DATE RANGE ABOVE AND CLICK SUBMIT\n";
	}

else
	{
	if ($shift == 'ALL') 
		{
		$Gct_default_start = "0";
		$Gct_default_stop = "2400";
		}
	else 
		{
		$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='$shift';";
		$rslt=mysql_query($stmt, $link);
		if ($DB) {$MAIN.="$stmt\n";}
		$calltimes_to_print = mysql_num_rows($rslt);
		if ($calltimes_to_print > 0)
			{
			$row=mysql_fetch_row($rslt);
			$Gct_default_start =	$row[3];
			$Gct_default_stop =		$row[4];
			$Gct_sunday_start =		$row[5];
			$Gct_sunday_stop =		$row[6];
			$Gct_monday_start =		$row[7];
			$Gct_monday_stop =		$row[8];
			$Gct_tuesday_start =	$row[9];
			$Gct_tuesday_stop =		$row[10];
			$Gct_wednesday_start =	$row[11];
			$Gct_wednesday_stop =	$row[12];
			$Gct_thursday_start =	$row[13];
			$Gct_thursday_stop =	$row[14];
			$Gct_friday_start =		$row[15];
			$Gct_friday_stop =		$row[16];
			$Gct_saturday_start =	$row[17];
			$Gct_saturday_stop =	$row[18];
			}
		else
			{
			$Gct_default_start = "0";
			$Gct_default_stop = "2400";
			}
		}
	$h=0;
	while ($h < 24)
		{
		$H_test = $h . "00";
		if ( ($H_test >= $Gct_default_start) and ($H_test <= $Gct_default_stop) )
			{
			$Hcalltime[$h]++;
			}
		$h++;
		}

	$query_date_BEGIN = "$query_date 00:00:00";   
	$query_date_END = "$end_date 23:59:59";


	$MAIN .= "Inbound Summary Hourly Report: $group_string          $NOW_TIME\n";
	$CSV_main.="Inbound Summary Hourly Report:,$NOW_TIME\n";


	$JS_text.="\n";

	if ($costformat > 0)
		{
		$ASCII_text.="
\n"; $inbound_cost = ($rawTOTtalk_min * $inbound_rate); $inbound_cost = sprintf("%8.2f", $inbound_cost); $ASCII_text.="INBOUND $query_date to $end_date,   $rawTOTtalk_min minutes at \$$inbound_rate = \$$inbound_cost\n"; exit; } if ($file_download > 0) { $FILE_TIME = date("Ymd-His"); $CSVfilename = "AST_CLOSERsummary_hourly_$US$FILE_TIME.csv"; $CSV_text=$CSV_main.$CSV_subreports; $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"; exit; } else { if ($report_display_type=="HTML") { $MAIN.=$GRAPH; $MAIN.=$sub_GRAPH; } else { $MAIN.=$ASCII_text; $MAIN.=$SUBoutput; } echo "$HEADER"; echo $JS_text; require("admin_header.php"); echo "$MAIN"; # echo "$SUBoutput"; $ENDtime = date("U"); $RUNtime = ($ENDtime - $STARTtime); echo "\n\nRun Time: $RUNtime seconds|$db_source\n"; echo ""; echo "
"; echo ""; } } ?>