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

<?php

	$adeiChannel = array(
		array(
			"aircoils__aircoils_rep__0__2",
			"aircoils__aircoils_rep__0__3",
			"aircoils__aircoils_rep__0__4",
			"aircoils__aircoils_rep__0__5",
			"aircoils__aircoils_rep__0__6",
			"aircoils__aircoils_rep__0__7",
			"aircoils__aircoils_rep__0__8",
			"aircoils__aircoils_rep__0__9",
			"aircoils__aircoils_rep__0__10",
			"aircoils__aircoils_rep__0__11",
			"aircoils__aircoils_rep__0__12",
			"aircoils__aircoils_rep__0__13",
			"aircoils__aircoils_rep__0__14",
			"aircoils__aircoils_rep__0__15",
			"aircoils__aircoils_rep__0__16",
			"aircoils__aircoils_rep__0__17"
		),
		array(
			"aircoils__aircoils_rep__0__34",
			"aircoils__aircoils_rep__0__35",
			"aircoils__aircoils_rep__0__36",
			"aircoils__aircoils_rep__0__37",
			"aircoils__aircoils_rep__0__38",
			"aircoils__aircoils_rep__0__39",
			"aircoils__aircoils_rep__0__40",
			"aircoils__aircoils_rep__0__41",
			"aircoils__aircoils_rep__0__42",
			"aircoils__aircoils_rep__0__43",
			"aircoils__aircoils_rep__0__44",
			"aircoils__aircoils_rep__0__45",
			"aircoils__aircoils_rep__0__46",
			"aircoils__aircoils_rep__0__47",
			"aircoils__aircoils_rep__0__48",
			"aircoils__aircoils_rep__0__49"
		),
		array(
			"aircoils__aircoils_rep__0__86",
			"aircoils__aircoils_rep__0__87",
			"aircoils__aircoils_rep__0__88",
			"aircoils__aircoils_rep__0__89",
			"aircoils__aircoils_rep__0__90",
			"aircoils__aircoils_rep__0__91",
			"aircoils__aircoils_rep__0__92",
			"aircoils__aircoils_rep__0__93",
			"aircoils__aircoils_rep__0__94",
			"aircoils__aircoils_rep__0__95",
			"aircoils__aircoils_rep__0__96",
			"aircoils__aircoils_rep__0__97",
			"aircoils__aircoils_rep__0__98",
			"aircoils__aircoils_rep__0__99",
			"aircoils__aircoils_rep__0__100",
			"aircoils__aircoils_rep__0__101"
		),
		array(
			"aircoils__aircoils_rep__0__100",
			"aircoils__aircoils_rep__0__101",
			"aircoils__aircoils_rep__0__102",
			"aircoils__aircoils_rep__0__103"
		),
		array(
			"fpd__katrin_rep__0__153",
			"fpd__katrin_rep__0__158"
		),
		array(
			"aircoils__aircoils_rep__1__3",
			"aircoils__aircoils_rep__1__4",
			"aircoils__aircoils_rep__1__9",
			"aircoils__aircoils_rep__1__10",
			"aircoils__aircoils_rep__1__18",
			"aircoils__aircoils_rep__1__14",
			"aircoils__aircoils_rep__1__16",
			"aircoils__aircoils_rep__1__19"
		),
		array(
			"fpd__katrin_rep__0__43",
			"fpd__katrin_rep__0__66",
			"fpd__katrin_rep__0__80",
			"fpd__katrin_rep__0__99",
			"fpd__katrin_rep__0__112",
			"fpd__katrin_rep__0__113",
			"fpd__katrin_rep__0__116",
			"fpd__katrin_rep__0__117",
			"fpd__katrin_rep__0__118",
			"fpd__katrin_rep__0__60",
			"fpd__katrin_rep__0__62",
			"fpd__katrin_rep__0__114",
			"fpd__katrin_rep__0__45"
		),
		array(
			"csms__ControlSystem_MS__432VAK_PumpPort2__54",
			"csms__ControlSystem_MS__432VAK_PumpPort2__9",
			"csms__ControlSystem_MS__432VAK_PumpPort2__18",
			"csms__ControlSystem_MS__432VAK_PumpPort2__27",
			"csms__ControlSystem_MS__432VAK_PumpPort2__99",
			"csms__ControlSystem_MS__432VAK_PumpPort2__102",
			"csms__ControlSystem_MS__432VAK_PumpPort2__105"
		),
		array(
			"csms__ControlSystem_MS__432VAK_PumpPort3__36",
			"csms__ControlSystem_MS__432VAK_PumpPort3__9",
			"csms__ControlSystem_MS__432VAK_PumpPort3__18",
			"csms__ControlSystem_MS__432VAK_PumpPort3__27",
			"csms__ControlSystem_MS__432VAK_PumpPort3__63",
			"csms__ControlSystem_MS__432VAK_PumpPort3__66",
			"csms__ControlSystem_MS__432VAK_PumpPort3__69"
		),
		array(
			"csms__ControlSystem_MS__432VAK_Tank__6",
			"csms__ControlSystem_MS__432VAK_Tank__9",
			"csms__ControlSystem_MS__432VAK_Tank__0",
			"csms__ControlSystem_MS__432VAK_Tank__15",
			"csms__ControlSystem_MS__432VAK_Tank__27",
			"csms__ControlSystem_MS__432VAK_Tank__30",
			"csms__ControlSystem_MS__432VAK_Tank__33",
			"csms__ControlSystem_MS__432VAK_Tank__39",
			"csms__ControlSystem_MS__432VAK_Tank__45",
			"csms__ControlSystem_MS__432VAK_Tank__48",
			"csms__ControlSystem_MS__432VAK_Tank__36"
		),
		array(
			"hv__katrin-hv_rep__0__87",
			"hv__katrin-hv_rep__0__86",
			"hv__katrin-hv_rep__0__95",
			"hv__katrin-hv_rep__0__94",
			"hv__katrin-hv_rep__0__71",
			"hv__katrin-hv_rep__0__70",
			"hv__katrin-hv_rep__0__79",
			"hv__katrin-hv_rep__0__78",
			"hv__katrin-hv_rep__0__63",
			"hv__katrin-hv_rep__0__62",
			"hv__katrin-hv_rep__0__55",
			"hv__katrin-hv_rep__0__54",
			"hv__katrin-hv_rep__0__132",
			"hv__katrin-hv_rep__0__131"
		),
		array(
			"hv__katrin-hv_rep__2__3",
			"hv__katrin-hv_rep__2__10",
			"hv__katrin-hv_rep__2__17",
			"hv__katrin-hv_rep__2__24",
			"hv__katrin-hv_rep__2__31",
			"hv__katrin-hv_rep__2__38",
			"hv__katrin-hv_rep__2__45",
			"hv__katrin-hv_rep__2__52",
			"hv__katrin-hv_rep__2__59",
			"hv__katrin-hv_rep__2__66",
			"hv__katrin-hv_rep__2__73",
			"hv__katrin-hv_rep__2__80",
			"hv__katrin-hv_rep__2__87",
			"hv__katrin-hv_rep__2__94",
			"hv__katrin-hv_rep__2__101",
			"hv__katrin-hv_rep__2__108",
			"hv__katrin-hv_rep__2__115",
			"hv__katrin-hv_rep__2__122",
			"hv__katrin-hv_rep__2__129",
			"hv__katrin-hv_rep__2__136",
			"hv__katrin-hv_rep__2__143",
			"hv__katrin-hv_rep__2__150",
			"hv__katrin-hv_rep__2__157",
			"hv__katrin-hv_rep__2__164"
		),
		array(
			"hv__katrin-hv_rep__2__2",
			"hv__katrin-hv_rep__2__9",
			"hv__katrin-hv_rep__2__16",
			"hv__katrin-hv_rep__2__23",
			"hv__katrin-hv_rep__2__30",
			"hv__katrin-hv_rep__2__37",
			"hv__katrin-hv_rep__2__44",
			"hv__katrin-hv_rep__2__51",
			"hv__katrin-hv_rep__2__58",
			"hv__katrin-hv_rep__2__65",
			"hv__katrin-hv_rep__2__72",
			"hv__katrin-hv_rep__2__79",
			"hv__katrin-hv_rep__2__86",
			"hv__katrin-hv_rep__2__93",
			"hv__katrin-hv_rep__2__100",
			"hv__katrin-hv_rep__2__107",
			"hv__katrin-hv_rep__2__114",
			"hv__katrin-hv_rep__2__121",
			"hv__katrin-hv_rep__2__128",
			"hv__katrin-hv_rep__2__135",
			"hv__katrin-hv_rep__2__142",
			"hv__katrin-hv_rep__2__149",
			"hv__katrin-hv_rep__2__156",
			"hv__katrin-hv_rep__2__163"
		),
		array(
			"hv__katrin-hv_rep__3__3",
			"hv__katrin-hv_rep__3__10",
			"hv__katrin-hv_rep__3__17",
			"hv__katrin-hv_rep__3__24",
			"hv__katrin-hv_rep__3__31",
			"hv__katrin-hv_rep__3__38",
			"hv__katrin-hv_rep__3__45",
			"hv__katrin-hv_rep__3__52",
			"hv__katrin-hv_rep__3__59",
			"hv__katrin-hv_rep__3__66",
			"hv__katrin-hv_rep__3__73",
			"hv__katrin-hv_rep__3__80",
			"hv__katrin-hv_rep__3__87",
			"hv__katrin-hv_rep__3__94",
			"hv__katrin-hv_rep__3__101",
			"hv__katrin-hv_rep__3__108",
			"hv__katrin-hv_rep__3__115",
			"hv__katrin-hv_rep__3__122",
			"hv__katrin-hv_rep__3__129",
			"hv__katrin-hv_rep__3__136",
			"hv__katrin-hv_rep__3__143",
			"hv__katrin-hv_rep__3__150",
			"hv__katrin-hv_rep__3__157",
			"hv__katrin-hv_rep__3__164"
		),
		array(
			"hv__katrin-hv_rep__3__2",
			"hv__katrin-hv_rep__3__9",
			"hv__katrin-hv_rep__3__16",
			"hv__katrin-hv_rep__3__23",
			"hv__katrin-hv_rep__3__30",
			"hv__katrin-hv_rep__3__37",
			"hv__katrin-hv_rep__3__44",
			"hv__katrin-hv_rep__3__51",
			"hv__katrin-hv_rep__3__58",
			"hv__katrin-hv_rep__3__65",
			"hv__katrin-hv_rep__3__72",
			"hv__katrin-hv_rep__3__79",
			"hv__katrin-hv_rep__3__86",
			"hv__katrin-hv_rep__3__93",
			"hv__katrin-hv_rep__3__100",
			"hv__katrin-hv_rep__3__107",
			"hv__katrin-hv_rep__3__114",
			"hv__katrin-hv_rep__3__121",
			"hv__katrin-hv_rep__3__128",
			"hv__katrin-hv_rep__3__135",
			"hv__katrin-hv_rep__3__142",
			"hv__katrin-hv_rep__3__149",
			"hv__katrin-hv_rep__3__156",
			"hv__katrin-hv_rep__3__163"
		),
		array(
			"csms__ControlSystem_MS__430KRYO_Baffel__21",
			"csms__ControlSystem_MS__430KRYO_Baffel__33",
			"csms__ControlSystem_MS__430KRYO_Baffel__51",
			"csms__ControlSystem_MS__430KRYO_Baffel__60",
			"csms__ControlSystem_MS__430KRYO_Baffel__66",
			"csms__ControlSystem_MS__430KRYO_Baffel__72"
		),
		array(
			"precmm0__PrecMagnet__NorthRing__0",
			"precmm0__PrecMagnet__NorthRing__1",
			"precmm0__PrecMagnet__NorthRing__2",
			"precmm0__PrecMagnet__NorthRing__7",
			"precmm0__PrecMagnet__NorthRing__8",
			"precmm0__PrecMagnet__NorthRing__9",
			"precmm0__PrecMagnet__NorthRing__14",
			"precmm0__PrecMagnet__NorthRing__15",
			"precmm0__PrecMagnet__NorthRing__16",
			"precmm0__PrecMagnet__NorthRing__21",
			"precmm0__PrecMagnet__NorthRing__22",
			"precmm0__PrecMagnet__NorthRing__23"
		),
		array(
			"precmm0__PrecMagnet__MidRing__0",
			"precmm0__PrecMagnet__MidRing__1",
			"precmm0__PrecMagnet__MidRing__2",
			"precmm0__PrecMagnet__MidRing__7",
			"precmm0__PrecMagnet__MidRing__8",
			"precmm0__PrecMagnet__MidRing__9",
			"precmm0__PrecMagnet__MidRing__14",
			"precmm0__PrecMagnet__MidRing__15",
			"precmm0__PrecMagnet__MidRing__16",
			"precmm0__PrecMagnet__MidRing__21",
			"precmm0__PrecMagnet__MidRing__22",
			"precmm0__PrecMagnet__MidRing__23",
			"precmm0__PrecMagnet__MidRing__28",
			"precmm0__PrecMagnet__MidRing__29",
			"precmm0__PrecMagnet__MidRing__30",
			"precmm0__PrecMagnet__MidRing__35",
			"precmm0__PrecMagnet__MidRing__36",
			"precmm0__PrecMagnet__MidRing__37"
		),
		array(
			"precmm0__PrecMagnet__SouthRing__0",
			"precmm0__PrecMagnet__SouthRing__1",
			"precmm0__PrecMagnet__SouthRing__2",
			"precmm0__PrecMagnet__SouthRing__7",
			"precmm0__PrecMagnet__SouthRing__8",
			"precmm0__PrecMagnet__SouthRing__9",
			"precmm0__PrecMagnet__SouthRing__14",
			"precmm0__PrecMagnet__SouthRing__15",
			"precmm0__PrecMagnet__SouthRing__16",
			"precmm0__PrecMagnet__SouthRing__21",
			"precmm0__PrecMagnet__SouthRing__22",
			"precmm0__PrecMagnet__SouthRing__23"
		),
		array(
			"fpd__katrin_rep__0__198",
			"fpd__katrin_rep__0__199",
			"fpd__katrin_rep__0__200"
		),
		array(
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__15",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__18",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__21",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__24",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__27",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__30",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__33",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__36",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__39",
			"cscryo__ControlSystem_Cryo__310DPS_Magnetsteuerung__42"
		),
		array(
			"csms__ControlSystem_MS__435HZ_Temperatur__24",
			"csms__ControlSystem_MS__435HZ_Temperatur__30",
			"csms__ControlSystem_MS__435HZ_Temperatur__39",
			"csms__ControlSystem_MS__435HZ_Temperatur__42"
		),
		array(
			"aircoils__aircoils_rep__2__2",
			"aircoils__aircoils_rep__2__3",
			"aircoils__aircoils_rep__2__4",
			"aircoils__aircoils_rep__2__5",
			"aircoils__aircoils_rep__2__6",
			"aircoils__aircoils_rep__2__7",
			"aircoils__aircoils_rep__2__8",
			"aircoils__aircoils_rep__2__9",
			"aircoils__aircoils_rep__2__10",
			"aircoils__aircoils_rep__2__11",
			"aircoils__aircoils_rep__2__12",
			"aircoils__aircoils_rep__2__13",
			"aircoils__aircoils_rep__2__14",
			"aircoils__aircoils_rep__2__15",
			"aircoils__aircoils_rep__2__16",
			"aircoils__aircoils_rep__2__17"
		),
		array(
			"aircoils__aircoils_rep__2__18",
			"aircoils__aircoils_rep__2__19",
			"aircoils__aircoils_rep__2__20",
			"aircoils__aircoils_rep__2__21",
			"aircoils__aircoils_rep__2__22",
			"aircoils__aircoils_rep__2__23",
			"aircoils__aircoils_rep__2__24",
			"aircoils__aircoils_rep__2__25",
			"aircoils__aircoils_rep__2__26",
			"aircoils__aircoils_rep__2__27",
			"aircoils__aircoils_rep__2__28",
			"aircoils__aircoils_rep__2__29",
			"aircoils__aircoils_rep__2__30",
			"aircoils__aircoils_rep__2__31",
			"aircoils__aircoils_rep__2__32",
			"aircoils__aircoils_rep__2__33"
		),
		array(
			"aircoils__aircoils_rep__2__57",
			"aircoils__aircoils_rep__2__58",
			"aircoils__aircoils_rep__2__43",
			"aircoils__aircoils_rep__2__44",
			"aircoils__aircoils_rep__2__45",
			"aircoils__aircoils_rep__2__46",
			"aircoils__aircoils_rep__2__47",
			"aircoils__aircoils_rep__2__48",
			"aircoils__aircoils_rep__2__49",
			"aircoils__aircoils_rep__2__50",
			"aircoils__aircoils_rep__2__51",
			"aircoils__aircoils_rep__2__52",
			"aircoils__aircoils_rep__2__53",
			"aircoils__aircoils_rep__2__54",
			"aircoils__aircoils_rep__2__55",
			"aircoils__aircoils_rep__2__56",
			"aircoils__aircoils_rep__2__38"
		)
	);



	$username = 'katrin';
	$password = 'neutrino';
	$context = stream_context_create(array(
		'http' => array(
			'header'  => "Authorization: Basic " . base64_encode("$username:$password"), "Connection: close\r\n"
		)
	));



	$handle = fopen("adei", "w");
	$content = "";

	for ($id = 0; $id < sizeof($adeiChannel); $id++)
	{
		$adeiChannels = "";
		for ($id2 = 0; $id2 < sizeof($adeiChannel[$id]); $id2++)
		{
			$adeiChannels = $adeiChannels . $adeiChannel[$id][$id2] . ",";
		}
		$adeiChannels = substr($adeiChannels, 0, strlen($adeiChannels) - 1);

      		$fileip = file_get_contents("https://adei-katrin.kaas.kit.edu/adei/services/getdata.php?db_server=virtual&db_name=srctree&db_group=-3&control_group=-3&virtual=srctree&srctree=" . $adeiChannels . "&window=60&format=csv", false, $context);
      		//$fileip = file_get_contents("http://ipekatrinbackupserv1.ipe.kit.edu/adei/services/getdata.php?db_server=virtual&db_name=srctree&db_group=-3&control_group=-3&virtual=srctree&srctree=" . $adeiChannels . "&window=60&format=csv", false, $context);
		//echo $fileip . "<br>";

		for ($id2 = sizeof($adeiChannel[$id]) - 1 ; $id2 > -1; $id2--)
		{
			$pos = strrpos($fileip, ",");
			$adeiValue[$id][$id2] = floatval(substr($fileip, $pos + 2));
			$fileip = substr($fileip, 0, $pos);
			//echo $id . "," . $id2 . "," . $adeiValue[$id][$id2] . "<br>";
			$content = $content . $adeiValue[$id][$id2] . " ";
			
		}

		$content = $content . "|";
	}

	fwrite($handle, $content);
	fclose($handle);

?>

</body>
</html>
