LICENSE: AGPLv2 # # CHANGES # # 190607-1522 - First build # 191013-0824 - Fixes for PHP7 # 200409-1634 - Fixed help popup # $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["query_date"])) {$query_date=$_GET["query_date"];} elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} if (isset($_GET["query_date_D"])) {$query_date_D=$_GET["query_date_D"];} elseif (isset($_POST["query_date_D"])) {$query_date_D=$_POST["query_date_D"];} if (isset($_GET["query_date_T"])) {$query_date_T=$_GET["query_date_T"];} elseif (isset($_POST["query_date_T"])) {$query_date_T=$_POST["query_date_T"];} if (isset($_GET["group"])) {$group=$_GET["group"];} elseif (isset($_POST["group"])) {$group=$_POST["group"];} if (isset($_GET["shift"])) {$shift=$_GET["shift"];} elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} if (isset($_GET["stage"])) {$stage=$_GET["stage"];} elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} if (isset($_GET["color"])) {$color=$_GET["color"];} elseif (isset($_POST["color"])) {$color=$_POST["color"];} if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} 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"];} 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"];} $DB = preg_replace('/[^0-9a-zA-Z]/','',$DB); $MT[0]=''; if (strlen($query_date_D) < 6) {$query_date_D = "00:00:00";} if (strlen($query_date_T) < 6) {$query_date_T = "23:59:59";} if (strlen($shift) < 1) {$shift = '0';} $shiftSQL = "$shift,1000"; $next_shift = ($shift + 1000); $prev_shift = ($shift - 1000); $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;} $query_date_BEGIN = "$query_date $query_date_D"; $query_date_END = "$query_date $query_date_T"; if (strlen($group) < 1) {$group = 'call_date desc';} if (strlen($color)<1) {$color='E6E6E6';} $report_name = 'SIP Event Report'; $db_source = 'M'; $JS_text="\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; require("chart_button.php"); echo "\n"; echo "\n"; echo "
\n"; echo "\n"; echo "\n"; echo ""._QXZ("$report_name")."\n"; echo ""; $short_header=1; require("admin_header.php"); echo "\n"; echo "\n"; echo ""._QXZ("$report_name")." $NWB#sip_event_report$NWE\n"; echo "
";
	}

if (strlen($query_date) < 1)
	{
	echo "";
	echo _QXZ("PLEASE SELECT A DATE AND TIME RANGE BELOW AND CLICK SUBMIT")."\n";
	}

else
	{
	$SIProws_ct=0;
	$stmt="SELECT count(*) from ".$vicidial_log_extended_table." where call_date <= '$query_date_END' and call_date >= '$query_date_BEGIN';";
	$rslt=mysql_to_mysqli($stmt, $link);
	if ($DB > 1) {echo "$stmt\n";}
	$VLEXrows_to_print = mysqli_num_rows($rslt);
	if ($VLEXrows_to_print > 0)
		{
		$row=mysqli_fetch_row($rslt);
		$SIProws_ct =		$row[0];
		}

	if ($file_download < 1)
		{
		$ASCII_text.=_QXZ("SIP Event Report",24).":    "._QXZ("Total Records").": $SIProws_ct    "._QXZ("Starting Record").": $shift                  $NOW_TIME ($db_source)\n";
		$ASCII_text.=_QXZ("Time range").": $query_date_BEGIN "._QXZ("to")." $query_date_END\n\n";
		}
	else
		{
		$file_output .= _QXZ("SIP Event Report",24).":    "._QXZ("Total Records").": $SIProws_ct    "._QXZ("Starting Record").": $shift                  $NOW_TIME ($db_source)\n";
		$file_output .= _QXZ("Time range").": $query_date_BEGIN "._QXZ("to")." $query_date_END\n\n";
		}

	$ASCII_text_table='';
	$statuses='-';
	$statusesTXT='';
	$statusesHEAD='';
	$statusesHTML='';
	$statusesFILE='';
	$statusesARY[0]='';
	$j=0;
	$dates='-';
	$datesARY[0]='';
	$date_namesARY[0]='';
	$k=0;

	$stmt="SELECT call_date,caller_code,invite_to_ring,ring_to_final,invite_to_final,last_event_code from ".$vicidial_log_extended_sip_table." where call_date <= '$query_date_END' and call_date >= '$query_date_BEGIN' order by $group limit $shiftSQL;";
	$rslt=mysql_to_mysqli($stmt, $link);
	if ($DB) {echo "$stmt\n";}
	$rows_to_print = mysqli_num_rows($rslt);
	$i=0;
	$SIPcall_date=array();
	$SIPcaller_code=array();
	$SIPinvite_to_ring=array();
	$SIPring_to_final=array();
	$SIPinvite_to_final=array();
	$SIPlast_event_code=array();
	while ($i < $rows_to_print)
		{
		$row=mysqli_fetch_row($rslt);
		$SIPcall_date[$i] =			$row[0];
		$SIPcaller_code[$i] =		$row[1];
		$SIPinvite_to_ring[$i] =	$row[2];
		$SIPring_to_final[$i] =		$row[3];
		$SIPinvite_to_final[$i] =	$row[4];
		$SIPlast_event_code[$i] =	$row[5];

		$i++;
		}


	### loop through every call, pick up details from other tables and put in display variable to be printed
	$i=0;
	$SIPuniqueid=array();
	$SIPserver_ip=array();
	$SIPlead_id=array();
	$SIPlength_in_sec=array();
	$SIPstatus=array();
	$SIPphone_number=array();
	$SIPcalled_count=array();
	$SIPuser=array();
	while ($i < $rows_to_print)
		{
		$stmt="SELECT uniqueid,server_ip,lead_id from ".$vicidial_log_extended_table." where caller_code = '$SIPcaller_code[$i]' order by call_date desc limit 1;";
		$rslt=mysql_to_mysqli($stmt, $link);
		if ($DB > 1) {echo "$stmt\n";}
		$VLErows_to_print = mysqli_num_rows($rslt);
		if ($VLErows_to_print > 0)
			{
			$row=mysqli_fetch_row($rslt);
			$SIPuniqueid[$i] =		$row[0];
			$SIPserver_ip[$i] =		$row[1];
			$SIPlead_id[$i] =		$row[2];
			}

		$stmt="SELECT length_in_sec,status,phone_number,called_count,user from ".$vicidial_log_table." where lead_id = '$SIPlead_id[$i]' and uniqueid='$SIPuniqueid[$i]' order by call_date desc limit 1;";
		$rslt=mysql_to_mysqli($stmt, $link);
		if ($DB > 1) {echo "$stmt\n";}
		$VLrows_to_print = mysqli_num_rows($rslt);
		if ($VLrows_to_print > 0)
			{
			$row=mysqli_fetch_row($rslt);
			$SIPlength_in_sec[$i] =	$row[0];
			$SIPstatus[$i] =		$row[1];
			$SIPphone_number[$i] =	$row[2];
			$SIPcalled_count[$i] =	$row[3];
			$SIPuser[$i] =			$row[4];
			}


		$ASCII_text_table.="| ".sprintf("%-27s", $SIPcall_date[$i]);
		$ASCII_text_table.=" | ".sprintf("%-20s", $SIPcaller_code[$i])."";
		$ASCII_text_table.=" | ".sprintf("%12s", $SIPinvite_to_ring[$i]);
		$ASCII_text_table.=" | ".sprintf("%12s", $SIPring_to_final[$i]);
		$ASCII_text_table.=" | ".sprintf("%12s", $SIPinvite_to_final[$i]);
		$ASCII_text_table.=" | ".sprintf("%20s", $SIPuniqueid[$i]);
		$ASCII_text_table.=" | ".sprintf("%15s", $SIPserver_ip[$i]);
		$ASCII_text_table.=" | ".sprintf("%9s", $SIPlead_id[$i])."";
		$ASCII_text_table.=" | ".sprintf("%5s", $SIPlength_in_sec[$i]);
		$ASCII_text_table.=" | ".sprintf("%10s", $SIPphone_number[$i]);
		$ASCII_text_table.=" | ".sprintf("%6s", $SIPstatus[$i]);
		$ASCII_text_table.=" | ".sprintf("%6s", $SIPcalled_count[$i]);
		$ASCII_text_table.=" |\n";

		$i++;
		}

	$ASCII_text.=_QXZ("Displaying Records").": $i                                       ";

	if ($shift > 999)
		{
		$ASCII_text.=""._QXZ("PREV")."   ";
		}
	if ($i > 999)
		{
		$ASCII_text.=""._QXZ("NEXT")."   ";
		}
	$ASCII_text.="\n";
	$ASCII_text.="+-----------------------------+----------------------+--------------+--------------+--------------+----------------------+-----------------+-----------+-------+------------+--------+--------+\n";
	$ASCII_text.="| "._QXZ("Date Time Microseconds",27);
	$ASCII_text.=" | "._QXZ("Caller Code",20);
	$ASCII_text.=" | "._QXZ("Post-Dial",12);
	$ASCII_text.=" | "._QXZ("Ring-Time",12);
	$ASCII_text.=" | "._QXZ("Total-Dial",12);
	$ASCII_text.=" | "._QXZ("UniqueID",20);
	$ASCII_text.=" | "._QXZ("Server IP",15);
	$ASCII_text.=" | "._QXZ("Lead ID",9);
	$ASCII_text.=" | "._QXZ("sec",5);
	$ASCII_text.=" | "._QXZ("Phone",10);
	$ASCII_text.=" | "._QXZ("Status",6);
	$ASCII_text.=" |"._QXZ("Call Ct",8);
	$ASCII_text.="|\n";
	$ASCII_text.="+-----------------------------+----------------------+--------------+--------------+--------------+----------------------+-----------------+-----------+-------+------------+--------+--------+\n";
	$ASCII_text.="$ASCII_text_table";
	$ASCII_text.="+----------------------------------------------------+--------------+--------------+--------------+----------------------+-----------------+-----------+-------+------------+--------+--------+\n";
	$ASCII_text.="|                                                    |              |              |              |\n";

	}


if ($file_download > 0)
	{
	$US='_';
	$FILE_TIME = date("Ymd-His");
	$CSVfilename = "SIP_EVENT_$US$FILE_TIME.csv";

	// 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 "$file_output";

	if ($db_source == 'S')
		{
		mysqli_close($link);
		$use_slave_server=0;
		$db_source = 'M';
		require("dbconnect_mysqli.php");
		}

	$endMS = microtime();
	$startMSary = explode(" ",$startMS);
	$endMSary = explode(" ",$endMS);
	$runS = ($endMSary[0] - $startMSary[0]);
	$runM = ($endMSary[1] - $startMSary[1]);
	$TOTALrun = ($runS + $runM);

	$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';";
	if ($DB) {echo "|$stmt|\n";}
	$rslt=mysql_to_mysqli($stmt, $link);

	exit;
	}

$JS_onload.="}\n";
if ($report_display_type=='HTML') {$JS_text.=$JS_onload;}
$JS_text.="\n";

echo "
"; echo "
"._QXZ("Date").":
"; echo "\n"; echo ""; ?>
"; echo "
"._QXZ("to")."
"; echo "
"; #echo _QXZ("Display as").":   
"; #echo "\n

"; echo "
"._QXZ("Sort").":
"; echo "
\n"; if ($archives_available=="Y") { echo ""._QXZ("Search archived data")."\n"; } echo "

\n"; echo "
        "; echo ""; echo ""._QXZ("REPORTS")." \n"; echo "
"; echo "
"; if ($report_display_type=="HTML") { echo $GRAPH_text; echo $JS_text; } else { echo $ASCII_text; } echo "\n"; if ($report_display_type=="TEXT" || !$report_display_type) { echo "\n"; echo "
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

	$m=0;
	$sort_order=array();
	while ($m < $k)
		{
		$sort_split = explode("-----",$TOPsort[$m]);
		$i = $sort_split[1];
		$sort_order[$m] = "$i";

		if ( ($TOPsortTALLY[$i] < 1) or ($TOPsortMAX < 1) )
			{echo "              \n";}
		else
			{
			echo "              ";
			$TOPsortPLOT = ( MathZDC($TOPsortTALLY[$i], $TOPsortMAX) * 120 );
			$h=0;
			while ($h <= $TOPsortPLOT)
				{
				echo " ";
				$h++;
				}
			echo "\n";
			}
		$m++;
		}

	echo "\n";
	}

if ($db_source == 'S')
	{
	mysqli_close($link);
	$use_slave_server=0;
	$db_source = 'M';
	require("dbconnect_mysqli.php");
	}

$endMS = microtime();
$startMSary = explode(" ",$startMS);
$endMSary = explode(" ",$endMS);
$runS = ($endMSary[0] - $startMSary[0]);
$runM = ($endMSary[1] - $startMSary[1]);
$TOTALrun = ($runS + $runM);

$stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_to_mysqli($stmt, $link);


?>