<?php
	// GPL
	// Hans Schou <chlor@schou.dk>
	header("Expires: Mon, 25 Jan 1999 05:00:00 GMT");   // Date in the past
	header("Last-Modified: ".gmdate("D, d M Y H:i:s")."GMT"); // modified
	header("Cache-Control: no-cache, must-revalidate");   // HTTP/1.1
	header("Pragma: no-cache"); // HTTP/1.0
	if ($TWO_TASK)
		$SID = $TWO_TASK;   // Oracle is running on a remote machine
	else
		$SID = $ORACLE_SID; // Oracle is running on this machine
              // Authenticate user, default Oracle username/password : system/manager
?><html>
<title>Who is using Oracle</title>
<meta http-equiv="Refresh" content="60"; URL="http://<?php echo $PHP_SELF; ?>">
<body bgcolor="#F0F0FF"><center>
<?php
	echo "<h2>Who is using Oracle?<br>Server: ".$SID;
	echo date("H:i:s, Y-m-d", time() )."<br>";
	echo  "User name: ".$PHP_AUTH_USER;
	echo  "</h2>\n";
	exit(0);
	// connect, default Oracle username/password: system/manager
	// To use another SID, enter user name  as: "system@ORCL"
	$conn = @OCILogon("system", "manager", $ORACLE_SID);
	if (!$conn) {
		echo  "<h1>Error: Unable to connect to Oracle</h1>\n";
	} else  {
		// prepare
		$sql = "SELECT osuser,machine,program FROM v\$session ORDER BY osuser, machine";
		$stmt = @OCIParse($conn, $sql);
		// execute sql statement
		if (@OCIExecute($stmt)) {
			$numcols = @OCINumCols($stmt);
			// fetch
			echo "<table border=\"5\" cellpadding=\"5\" bgcolor=\"#F0F0F0\">\n";
			echo "<caption>".@OCIServerVersion($conn)."</caption>\n";
			echo "<tr><th>".@OCIColumnname($stmt,1)."<br>".OCIColumnType($stmt,1)."</th>";
			echo "<th>".@OCIColumnname($stmt,2)."<br>".OCIColumnType($stmt,2)."</th>";
			echo "<th>".@OCIColumnname($stmt,3)."<br>".OCIColumnType($stmt,3)."</th></tr>\n";
#			while (@OCIFetchInto($stmt, &$result, OCI_ASSOC)) {
#				echo  "<tr><td>";
#				echo  $result['OSUSER'];
#				echo  "</td><td>";
#				echo  $result['MACHINE'];
#				echo  "</td><td>";
#				echo  $result['PROGRAM'];
#				echo  "</td></tr>\n";
#			}
			echo  "</tr></table>\n";
			echo  "<p>\n";
		}
		@OCIFreeStatement($stmt);
		@OCILogoff($conn);
	}
	// Display source file if exists
	if (file_exists($fn = basename($PHP_SELF."s") ))
		echo  "<i><a href=\"".$fn. "\">Source file: $fn</a></i>\n";
	else
		echo  "<i>Source is not available</i>\n";
?>
</center>
</body></html>
