index.php 14 KB

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