<html>
<head>
<title>
</title>
</head>
<body>

<?php

	function getXMLValue($name, $fileip)
	{
		$posA = strpos($fileip, '<' . $name . '>');
		$posB = strpos($fileip, '</' . $name . '>');
		$len = strlen($name) + 2;
		return substr($fileip, $posA + $len, $posB - $posA - $len);
	}



	// ########## DAQ MACHINES ##########

	$daqChannel = array(369, 361, 362); // 369: FPD; 361: MUON; 362: MOS

	for ($id = 0; $id < sizeof($daqChannel); $id++)
	{
		$fileip = file_get_contents("http://katrin.kit.edu/OrcaWeb/query.php?tag=runInfo&query=select%20*%20from%20machines,runs%20where%20runs.machine_id=" . $daqChannel[$id] . "%20and%20machines.machine_id=" . $daqChannel[$id], false);

		$daqRun[$id] = getXMLValue("run", $fileip);
		$daqSubrun[$id] = getXMLValue("subrun", $fileip);
		$daqElapsed[$id] = getXMLValue("elapsedTime", $fileip);
		$daqTogo[$id] = getXMLValue("timeToGo", $fileip);
		$daqState[$id] = getXMLValue("state", $fileip);
		$daqRepeat[$id] = getXMLValue("repeatRun", $fileip);
		$daqOffline[$id] = getXMLValue("offline", $fileip);
		$daqTimed[$id] = getXMLValue("timedRun", $fileip);
	}



	// ########## PULSERS ##########

	// FPD

	$fileip = file_get_contents("http://katrin.kit.edu/OrcaWeb/query.php?tag=dataList&query=select%20dataset_id,name,counts%20from%20Histogram1Ds%20where%20machine_id=" . $daqChannel[0] . "%20ORDER%20BY%20name", false);

	$pulser[0] = getXMLValue("counts", substr($fileip, strpos($fileip, 'FLT,Energy,Crate  0,Station 12,Channel  1')));
	$pulser[1] = getXMLValue("counts", substr($fileip, strpos($fileip, 'FLT,Energy,Crate  0,Station 19,Channel  0')));

	// MUON

	$fileip = file_get_contents("http://katrin.kit.edu/OrcaWeb/query.php?tag=dataList&query=select%20dataset_id,name,counts%20from%20Histogram1Ds%20where%20machine_id=" . $daqChannel[1] . "%20ORDER%20BY%20name", false);

	$pulser[2] = getXMLValue("counts", substr($fileip, strpos($fileip, 'FLT,Energy,Crate  0,Station 18,Channel  0')));



	echo $pulser[0] . " " . $pulser[1] . " " . $pulser[2] . "<br>";
	echo "OK";

?>

</body>