index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <html>
  2. <head>
  3. <link rel="shortcut icon" href="../pics/KATRINlogo.ico" />
  4. <title>High-Voltage Patch-Panel Configuration</title>
  5. <style type="text/css">
  6. body { font-family:Arial; }
  7. td { text-align:center; }
  8. td.left { text-align:left; }
  9. a:link { text-decoration:none; }
  10. a:visited { text-decoration:none; }
  11. a:hover { text-decoration:none; }
  12. a:active { text-decoration:none; }
  13. a:focus { text-decoration:none; }
  14. td.even {
  15. background-color: #C8C8C8;
  16. }
  17. td.odd {
  18. background-color: #FFFFFF;
  19. }
  20. tr.highlight:hover,
  21. tr.highlight:hover td {
  22. background-color: #F0E68C !important;
  23. }
  24. .container {
  25. display: block;
  26. position: relative;
  27. margin: 5px;
  28. margin-top: -7px;
  29. padding-left: 14px;
  30. cursor: pointer;
  31. font-size: 22px;
  32. -webkit-user-select: none;
  33. -moz-user-select: none;
  34. -ms-user-select: none;
  35. user-select: none;
  36. }
  37. /* Hide the browser's default checkbox */
  38. .container input {
  39. position: absolute;
  40. opacity: 0;
  41. cursor: pointer;
  42. height: 0;
  43. width: 0;
  44. }
  45. /* Create a custom checkbox */
  46. .checkmark {
  47. position: absolute;
  48. top: 0;
  49. left: 0;
  50. height: 10px;
  51. width: 10px;
  52. background-color: #eee;
  53. border: 2px solid #ddd;
  54. border-radius: 7px;
  55. }
  56. /* On mouse-over, add a grey background color */
  57. .container:hover input ~ .checkmark {
  58. background-color: #FF8C00;
  59. border: 2px solid black;
  60. }
  61. /* On mouse-over, add a grey background color */
  62. .container:hover input:checked ~ .checkmark {
  63. background-color: #0000CD;
  64. border: 2px solid #0000CD;
  65. }
  66. /* When the checkbox is checked, add a blue background */
  67. .container input:checked ~ .checkmark {
  68. background-color: #0000CD;
  69. border: 2px solid #eee;
  70. }
  71. /* Create the checkmark/indicator (hidden when not checked) */
  72. .checkmark:after {
  73. content: "";
  74. position: absolute;
  75. display: none;
  76. }
  77. /* Show the checkmark when checked */
  78. .container input:checked ~ .checkmark:after {
  79. display: block;
  80. }
  81. /* Style the checkmark/indicator */
  82. .container .checkmark:after {
  83. left: 2px;
  84. top: 2px;
  85. width: 2px;
  86. height: 2px;
  87. border: solid white;
  88. border-width: 1px 2px 3px 2px;
  89. border-radius: 3px;
  90. }
  91. </style>
  92. </head>
  93. <body>
  94. <?php
  95. // offset between patch-panel channel $ch and adei channel $adei: $adei = $ch + $offset
  96. $offset = 2;
  97. // main-spectrometer rings
  98. $rings = array( "w02o", "w02i", "w03o", "w03i", "w04o", "w04i", "w05o", "w05i", "w06o", "w06i", "w07o", "w07i", "w12o", "w12i", "w13o", "w13i", "w14o", "w14i", "w15o", "w15i", "w16o", "w16i", "e02o", "e02i", "e03o", "e03i", "e04o", "e04i", "e05o", "e05i", "e06o", "e06i", "e07o", "e07i", "e12o", "e12i", "e13o", "e13i", "e14o", "e14i", "e15o", "e15i", "e16o", "e16i" );
  99. ?>
  100. <?php
  101. // submit button
  102. if ($_POST["ok"] == "submit")
  103. {
  104. // write TXT patch-panel configuration
  105. $config = $_POST["configurationname"] != "" ? $_POST["configurationname"] : $_POST["configurationload"];
  106. $author = $_POST["author"] != "" ? $_POST["author"] : "(anonymous)";
  107. //$time = strtotime($_POST["validfrom"]);
  108. $time = strtotime($_POST["validfrom-date"] . " " . $_POST["validfrom-time"]);
  109. if ($time === FALSE) $filename = time() . ".txt"; else $filename = $time . ".txt";
  110. $handle = fopen("data/" . $filename, "w");
  111. if ($handle)
  112. {
  113. $content = "";
  114. for ($id = 0; $id < 44; $id++)
  115. {
  116. if ($_POST[$rings[$id]] == 22) $tempcontent = "IE";
  117. else $tempcontent = floatval($_POST[$rings[$id]]) + $offset;
  118. $content = $content . $tempcontent . "\r\n";
  119. }
  120. fwrite($handle, $content);
  121. fclose($handle);
  122. }
  123. // copy for SDS-STATUS-DISPLAY
  124. copy("data/" . $filename, "data/activeIEconfig.txt");
  125. // write CONF patch-panel configuration
  126. if ($_POST["configurationname"] != "")
  127. {
  128. $filename = $_POST["configurationname"] . ".conf";
  129. $handle = fopen("data/" . $filename, "w");
  130. if ($handle)
  131. {
  132. $content = "";
  133. for ($id = 0; $id < 44; $id++)
  134. {
  135. $tempcontent = floatval($_POST[$rings[$id]]);
  136. $content = $content . $tempcontent . "\r\n";
  137. }
  138. fwrite($handle, $content);
  139. fclose($handle);
  140. }
  141. }
  142. // update KDB database
  143. if (isset($_POST["database"])) {
  144. sleep(1);
  145. //require '../update_database.php';
  146. if ($time === FALSE) {
  147. shell_exec('cd .. ; php ./update_database.php "' . $config . '" "' . $author . '"');
  148. }
  149. else {
  150. shell_exec('cd .. ; php ./update_database.php "' . $config . '" "' . $author . '" "' . date('Y-m-d H:i:s', $time) . '"');
  151. }
  152. }
  153. }
  154. ?>
  155. <?php
  156. // load configuration
  157. $check = array( 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
  158. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22 );
  159. if (!array_key_exists("configurationload", $_POST))
  160. $_POST["configurationload"] = "(active configuration)";
  161. #echo $_POST["configurationload"];
  162. if ($_POST["configurationload"] == "(active configuration)")
  163. {
  164. shell_exec('cd .. ; php ./poll_database.php');
  165. $handle = fopen("data/activeIEconfig.txt", "r");
  166. if ($handle)
  167. {
  168. $id = 0;
  169. while (($buffer = fgets($handle, 4096)) !== false)
  170. {
  171. $buffer = trim($buffer);
  172. if ($buffer == 'IE')
  173. $check[$id++] = 22;
  174. else
  175. $check[$id++] = intval($buffer) - 2;
  176. }
  177. fclose($handle);
  178. }
  179. }
  180. else if ($_POST["configurationload"] != "(new configuration)")
  181. {
  182. $filename = $_POST["configurationload"] . ".conf";
  183. $handle = fopen("data/" . $filename, "r");
  184. if ($handle)
  185. {
  186. $id = 0;
  187. while (($buffer = fgets($handle, 4096)) !== false)
  188. {
  189. $buffer = trim($buffer);
  190. $check[$id++] = $buffer;
  191. }
  192. fclose($handle);
  193. }
  194. }
  195. ?>
  196. <?php
  197. $adeiChannel[0] = array( "hv__katrin-hv_rep__0__95", "hv__katrin-hv_rep__0__71", "hv__katrin-hv_rep__0__79" );
  198. for ($id = 0; $id < 24; $id++)
  199. {
  200. $adeiChannel[1][$id] = "hv__katrin-hv_rep__1__" . (7 * $id + 3 + 7 * $offset);
  201. $adeiChannel[2][$id] = "hv__katrin-hv_rep__2__" . (7 * $id + 3 + 7 * $offset);
  202. }
  203. $username = getenv('PHP_ADEI_USERNAME');
  204. $password = getenv('PHP_ADEI_PASSWORD');
  205. $context = stream_context_create(array(
  206. 'http' => array(
  207. 'header' => "Authorization: Basic " . base64_encode("$username:$password")
  208. )
  209. ));
  210. for ($id = 0; $id < sizeof($adeiChannel); $id++)
  211. {
  212. $adeiChannels = "";
  213. for ($id2 = 0; $id2 < sizeof($adeiChannel[$id]); $id2++)
  214. {
  215. $adeiChannels = $adeiChannels . $adeiChannel[$id][$id2] . ",";
  216. }
  217. $adeiChannels = substr($adeiChannels, 0, strlen($adeiChannels) - 1);
  218. $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);
  219. //echo $fileip . "<br>";
  220. for ($id2 = sizeof($adeiChannel[$id]) - 1 ; $id2 > -1; $id2--)
  221. {
  222. $pos = strrpos($fileip, ",");
  223. $adeiValue[$id][$id2] = floatval(substr($fileip, $pos + 2));
  224. $fileip = substr($fileip, 0, $pos);
  225. //echo $id . "," . $id2 . "," . $adeiValue[$id][$id2] . "<br>";
  226. }
  227. }
  228. ?>
  229. <form method="post" action="index.php" name="myform">
  230. <font size="6">
  231. <a href="../index.php" title="Back to main page">
  232. <img style="margin-right: .5em; margin-bottom: -8px" src="../pics/katrin_logo_round.png" width="40px" height="40px">
  233. <a>
  234. <b>High-Voltage Patch-Panel Configuration</b>
  235. </font>
  236. <br><br>
  237. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  238. <tr>
  239. <td><b>configuration</b></td>
  240. <td>
  241. <select name="configurationload" size="1" onchange="myform.submit();">
  242. <option>(active configuration)</option>
  243. <?php
  244. if ($_POST["configurationload"] == "(new configuration)") echo '<option selected>'; else echo '<option>';
  245. echo '(new configuration)</option>';
  246. foreach (glob("data/*.conf") as $filename)
  247. {
  248. $buffer = substr($filename, 5, strlen($filename) - 10);
  249. if ($_POST["configurationload"] == $buffer) echo '<option selected>'; else echo '<option>';
  250. echo $buffer . '</option>';
  251. }
  252. ?>
  253. </select>
  254. </td>
  255. </tr>
  256. <tr>
  257. <td>name</td>
  258. <td>
  259. <input type="text" name="configurationname" size="35">
  260. </td>
  261. </tr>
  262. </table>
  263. <br>
  264. <table border="0" cellpadding="0" cellspacing="0">
  265. <tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>
  266. <tr>
  267. <th bgcolor="#C8C8C8" colspan="22"><b>W E S T</b></th>
  268. <th colspan="3"><b>PATCH PANEL</b></th>
  269. <th bgcolor="#C8C8C8" colspan="22"><b>E A S T</b></th>
  270. </tr>
  271. <tr>
  272. <?php
  273. for ($id=2; $id<7; $id++) {
  274. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  275. echo '<td class="highlight ' . $class . '" colspan="2">0' . $id . '</td>';
  276. }
  277. echo '<td colspan="2">07-11</td>';
  278. for ($id=12; $id<17; $id++) {
  279. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  280. echo '<td class="highlight ' . $class . '" colspan="2">' . $id . '</td>';
  281. }
  282. echo '<td>&nbsp;ADEI&nbsp;</td>';
  283. echo '<td>&nbsp;CH&nbsp;</td>';
  284. echo '<td>&nbsp;ADEI&nbsp;</td>';
  285. for ($id=2; $id<7; $id++) {
  286. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  287. echo '<td class="highlight ' . $class . '" colspan="2">0' . $id . '</td>';
  288. }
  289. echo '<td colspan="2">07-11</td>';
  290. for ($id=12; $id<17; $id++) {
  291. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  292. echo '<td class="highlight ' . $class . '" colspan="2">' . $id . '</td>';
  293. }
  294. ?>
  295. </tr>
  296. <tr>
  297. <?php
  298. for ($id=0; $id<11; $id++) {
  299. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  300. echo '<td class="highlight ' . $class . '">o</td><td class="highlight ' . $class . '">i</td>';
  301. }
  302. echo '<td></td>';
  303. echo '<td></td>';
  304. echo '<td></td>';
  305. for ($id=0; $id<11; $id++) {
  306. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  307. echo '<td class="highlight ' . $class . '">o</td><td class="highlight ' . $class . '">i</td>';
  308. }
  309. ?>
  310. </tr>
  311. <?php
  312. for ($ch=0; $ch<23; $ch++)
  313. {
  314. if ($ch % 5 == 0) echo '<tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>';
  315. $text = str_pad($ch, 2, 0, STR_PAD_LEFT);
  316. echo '<tr class="highlight">';
  317. for ($id=0; $id<22; $id++)
  318. {
  319. //if ($id % 4 == 2 || $id % 4 == 3) $color = "#FFFFFF"; else $color = "#C8C8C8";
  320. if ($id % 4 == 2 || $id % 4 == 3) $class = "odd"; else $class = "even";
  321. $checked = "";
  322. if ($check[$id] == $ch) $checked = 'checked="checked"';
  323. echo '<td class="highlight ' . $class . '"><label class="container"><input type="radio" name="' . $rings[$id] . '" value="' . $ch . '" ' . $checked . '><span class="checkmark"></span></label></td>';
  324. }
  325. $value = $adeiValue[1][$ch];
  326. if ($ch == 22) $value = $adeiValue[0][0] + $adeiValue[0][1];
  327. echo '<td>' . sprintf('%.0F', $value) . '</td>';
  328. echo '<th><b>';
  329. if ($ch == 22) echo 'IE';
  330. else echo $text;
  331. echo '</b></th>';
  332. $value = $adeiValue[2][$ch];
  333. if ($ch == 22) $value = $adeiValue[0][0] + $adeiValue[0][2];
  334. echo '<td>' . sprintf('%.0F', $value) . '</td>';
  335. for ($id=22; $id<44; $id++)
  336. {
  337. //if ($id % 4 == 0 || $id % 4 == 1) $color = "#FFFFFF"; else $color = "#C8C8C8";
  338. if ($id % 4 == 2 || $id % 4 == 3) $class = "even"; else $class = "odd";
  339. $checked = "";
  340. if ($check[$id] == $ch) $checked = 'checked="checked"';
  341. echo '<td class="highlight ' . $class . '"><label class="container"><input type="radio" name="' . $rings[$id] . '" value="' . $ch . '" ' . $checked . '><span class="checkmark"></span></label></td>';
  342. }
  343. echo '</tr>';
  344. }
  345. ?>
  346. <tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>
  347. </table>
  348. <br>
  349. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  350. <tr>
  351. <td><b>valid from</b></td>
  352. <td>
  353. <!-- <input type="text" name="validfrom" size="19" maxlength="19"> (YYYY-MM-DD HH:MM:SS) -->
  354. <input type="date" name="validfrom-date">
  355. <input type="time" name="validfrom-time">
  356. </td>
  357. </tr>
  358. </table>
  359. <br>
  360. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  361. <tr>
  362. <td width="200px"><b>elog entry</b></td>
  363. <td class="left">
  364. <input type="checkbox" name="elog" value="yes"> submit to ELOG
  365. </td>
  366. </tr>
  367. <tr>
  368. <td><b>database entry</b></td>
  369. <td class="left">
  370. <input type="checkbox" name="database" value="yes"> submit to KDB
  371. </td>
  372. </tr>
  373. <tr>
  374. <td>author<br/><sup>(click twice to open drop-down)</sup></td>
  375. <td class="left">
  376. <!--<select name="author" size="1">-->
  377. <input type="text" list="authorlist" name="author" size="50"/>
  378. <datalist id="authorlist">
  379. <option>---</option>
  380. <option>B. Bieringer</option>
  381. <option>C. Rodenbeck</option>
  382. <option>T. Thuemmler</option>
  383. <option>S. Wuestling</option>
  384. </datalist>
  385. <!--</select>-->
  386. </td>
  387. </tr>
  388. <tr>
  389. <td>comments</td>
  390. <td class="left">
  391. <textarea name="comments" cols="50" rows="5"></textarea>
  392. </td>
  393. </tr>
  394. </table>
  395. <br>
  396. <input type="submit" name="ok" value="submit">
  397. <input type="reset" value="reset">
  398. </form>
  399. </body>
  400. </html>