index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. // submit message to elog (currently main spec elog)
  165. if (isset($_POST["elog"])) {
  166. sleep(1);
  167. // apache web server runs on UTF-8, but elog runs on ISO 8859-1, so all stings posted to the elog need to be converted via utf8_decode();
  168. $ElogAuthor = utf8_decode($author);
  169. $ElogConfig = utf8_decode($config);
  170. $ElogTime = utf8_decode(date('Y-m-d H:i:s', $time));
  171. $ElogEntry = 'Patch panel changed to ' . $ElogConfig . ' on ' . $ElogTime;
  172. $ToBeExec = 'echo "' . $ElogEntry . '" | elog -h localhost -p 8080 -l main-spectrometer -v -u sds-operator mainspec.13 -a Author="' . $ElogAuthor . '" -a Email=katrin-sds-status@lists.kit.edu -a Type=Routine -a Category=General -a Subject="' . $ElogConfig . '" -x -n 2';
  173. echo "Message for Elog: ".$ToBEExec.$PHP_EOL;
  174. // currently not working due to server change
  175. //shell_exec($ToBeExec);
  176. }
  177. }
  178. ?>
  179. <?php
  180. // load configuration
  181. $check = array( 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
  182. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22 );
  183. if (!array_key_exists("configurationload", $_POST))
  184. $_POST["configurationload"] = "(active configuration)";
  185. #echo $_POST["configurationload"];
  186. if ($_POST["configurationload"] == "(active configuration)")
  187. {
  188. shell_exec('cd .. ; php ./poll_database.php');
  189. $handle = fopen("data/activeIEconfig.txt", "r");
  190. if ($handle)
  191. {
  192. $id = 0;
  193. while (($buffer = fgets($handle, 4096)) !== false)
  194. {
  195. $buffer = trim($buffer);
  196. if ($buffer == 'IE')
  197. $check[$id++] = 22;
  198. else
  199. $check[$id++] = intval($buffer) - 2;
  200. }
  201. fclose($handle);
  202. }
  203. }
  204. else if ($_POST["configurationload"] != "(new configuration)")
  205. {
  206. $filename = $_POST["configurationload"] . ".conf";
  207. $handle = fopen("data/" . $filename, "r");
  208. if ($handle)
  209. {
  210. $id = 0;
  211. while (($buffer = fgets($handle, 4096)) !== false)
  212. {
  213. $buffer = trim($buffer);
  214. $check[$id++] = $buffer;
  215. }
  216. fclose($handle);
  217. }
  218. }
  219. ?>
  220. <?php
  221. $adeiChannel[0] = array( "hv__katrin-hv_rep__0__95", "hv__katrin-hv_rep__0__71", "hv__katrin-hv_rep__0__79" );
  222. for ($id = 0; $id < 24; $id++)
  223. {
  224. $adeiChannel[1][$id] = "hv__katrin-hv_rep__1__" . (7 * $id + 3 + 7 * $offset);
  225. $adeiChannel[2][$id] = "hv__katrin-hv_rep__2__" . (7 * $id + 3 + 7 * $offset);
  226. }
  227. $username = getenv('PHP_ADEI_USERNAME');
  228. $password = getenv('PHP_ADEI_PASSWORD');
  229. $context = stream_context_create(array(
  230. 'http' => array(
  231. 'header' => "Authorization: Basic " . base64_encode("$username:$password")
  232. )
  233. ));
  234. for ($id = 0; $id < sizeof($adeiChannel); $id++)
  235. {
  236. $adeiChannels = "";
  237. for ($id2 = 0; $id2 < sizeof($adeiChannel[$id]); $id2++)
  238. {
  239. $adeiChannels = $adeiChannels . $adeiChannel[$id][$id2] . ",";
  240. }
  241. $adeiChannels = substr($adeiChannels, 0, strlen($adeiChannels) - 1);
  242. $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);
  243. //echo $fileip . "<br>";
  244. for ($id2 = sizeof($adeiChannel[$id]) - 1 ; $id2 > -1; $id2--)
  245. {
  246. $pos = strrpos($fileip, ",");
  247. $adeiValue[$id][$id2] = floatval(substr($fileip, $pos + 2));
  248. $fileip = substr($fileip, 0, $pos);
  249. //echo $id . "," . $id2 . "," . $adeiValue[$id][$id2] . "<br>";
  250. }
  251. }
  252. ?>
  253. <form method="post" action="index.php" name="myform">
  254. <font size="6">
  255. <a href="../index.php" title="Back to main page">
  256. <img style="margin-right: .5em; margin-bottom: -8px" src="../pics/katrin_logo_round.png" width="40px" height="40px">
  257. <a>
  258. <b>High-Voltage Patch-Panel Configuration</b>
  259. </font>
  260. <br><br>
  261. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  262. <tr>
  263. <td><b>configuration</b></td>
  264. <td>
  265. <select name="configurationload" size="1" onchange="myform.submit();">
  266. <option>(active configuration)</option>
  267. <?php
  268. if ($_POST["configurationload"] == "(new configuration)") echo '<option selected>'; else echo '<option>';
  269. echo '(new configuration)</option>';
  270. foreach (glob("data/*.conf") as $filename)
  271. {
  272. $buffer = substr($filename, 5, strlen($filename) - 10);
  273. if ($_POST["configurationload"] == $buffer) echo '<option selected>'; else echo '<option>';
  274. echo $buffer . '</option>';
  275. }
  276. ?>
  277. </select>
  278. </td>
  279. </tr>
  280. <tr>
  281. <td>name</td>
  282. <td>
  283. <input type="text" name="configurationname" size="35">
  284. </td>
  285. </tr>
  286. </table>
  287. <br>
  288. <table border="0" cellpadding="0" cellspacing="0">
  289. <tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>
  290. <tr>
  291. <th bgcolor="#C8C8C8" colspan="22"><b>W E S T</b></th>
  292. <th colspan="3"><b>PATCH PANEL</b></th>
  293. <th bgcolor="#C8C8C8" colspan="22"><b>E A S T</b></th>
  294. </tr>
  295. <tr>
  296. <?php
  297. for ($id=2; $id<7; $id++) {
  298. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  299. echo '<td class="highlight ' . $class . '" colspan="2">0' . $id . '</td>';
  300. }
  301. echo '<td colspan="2">07-11</td>';
  302. for ($id=12; $id<17; $id++) {
  303. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  304. echo '<td class="highlight ' . $class . '" colspan="2">' . $id . '</td>';
  305. }
  306. echo '<td>&nbsp;ADEI&nbsp;</td>';
  307. echo '<td>&nbsp;CH&nbsp;</td>';
  308. echo '<td>&nbsp;ADEI&nbsp;</td>';
  309. for ($id=2; $id<7; $id++) {
  310. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  311. echo '<td class="highlight ' . $class . '" colspan="2">0' . $id . '</td>';
  312. }
  313. echo '<td colspan="2">07-11</td>';
  314. for ($id=12; $id<17; $id++) {
  315. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  316. echo '<td class="highlight ' . $class . '" colspan="2">' . $id . '</td>';
  317. }
  318. ?>
  319. </tr>
  320. <tr>
  321. <?php
  322. for ($id=0; $id<11; $id++) {
  323. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  324. echo '<td class="highlight ' . $class . '">o</td><td class="highlight ' . $class . '">i</td>';
  325. }
  326. echo '<td></td>';
  327. echo '<td></td>';
  328. echo '<td></td>';
  329. for ($id=0; $id<11; $id++) {
  330. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  331. echo '<td class="highlight ' . $class . '">o</td><td class="highlight ' . $class . '">i</td>';
  332. }
  333. ?>
  334. </tr>
  335. <?php
  336. for ($ch=0; $ch<23; $ch++)
  337. {
  338. if ($ch % 5 == 0) echo '<tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>';
  339. $text = str_pad($ch, 2, 0, STR_PAD_LEFT);
  340. echo '<tr class="highlight">';
  341. for ($id=0; $id<22; $id++)
  342. {
  343. //if ($id % 4 == 2 || $id % 4 == 3) $color = "#FFFFFF"; else $color = "#C8C8C8";
  344. if ($id % 4 == 2 || $id % 4 == 3) $class = "odd"; else $class = "even";
  345. if ($ch == 22) $class .= " common";
  346. $checked = "";
  347. if ($check[$id] == $ch) $checked = 'checked="checked"';
  348. echo '<td class="highlight ' . $class . '"><label class="container"><input type="radio" name="' . $rings[$id] . '" value="' . $ch . '" ' . $checked . '><span class="checkmark"></span></label></td>';
  349. }
  350. $value = $adeiValue[1][$ch];
  351. if ($ch == 22) $value = $adeiValue[0][0] + $adeiValue[0][1];
  352. echo '<td>' . sprintf('%.0F', $value) . '</td>';
  353. echo '<th><b>';
  354. if ($ch == 22) echo 'IE';
  355. else echo $text;
  356. echo '</b></th>';
  357. $value = $adeiValue[2][$ch];
  358. if ($ch == 22) $value = $adeiValue[0][0] + $adeiValue[0][2];
  359. echo '<td>' . sprintf('%.0F', $value) . '</td>';
  360. for ($id=22; $id<44; $id++)
  361. {
  362. //if ($id % 4 == 0 || $id % 4 == 1) $color = "#FFFFFF"; else $color = "#C8C8C8";
  363. if ($id % 4 == 2 || $id % 4 == 3) $class = "even"; else $class = "odd";
  364. if ($ch == 22) $class .= " common";
  365. $checked = "";
  366. if ($check[$id] == $ch) $checked = 'checked="checked"';
  367. echo '<td class="highlight ' . $class . '"><label class="container"><input type="radio" name="' . $rings[$id] . '" value="' . $ch . '" ' . $checked . '><span class="checkmark"></span></label></td>';
  368. }
  369. echo '</tr>';
  370. }
  371. ?>
  372. <tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>
  373. </table>
  374. <br>
  375. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  376. <tr>
  377. <td><b>valid from</b></td>
  378. <td>
  379. <!-- <input type="text" name="validfrom" size="19" maxlength="19"> (YYYY-MM-DD HH:MM:SS) -->
  380. <input type="date" name="validfrom-date">
  381. <input type="time" name="validfrom-time">
  382. </td>
  383. </tr>
  384. </table>
  385. <br>
  386. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  387. <tr>
  388. <td width="200px"><b>elog entry</b></td>
  389. <td class="left">
  390. <input type="checkbox" name="elog" value="yes"> submit to ELOG
  391. </td>
  392. </tr>
  393. <tr>
  394. <td><b>database entry</b></td>
  395. <td class="left">
  396. <input type="checkbox" name="database" value="yes"> submit to KDB
  397. </td>
  398. </tr>
  399. <tr>
  400. <td>author<br/><sup>(click twice to open drop-down)</sup></td>
  401. <td class="left">
  402. <!--<select name="author" size="1">-->
  403. <input type="text" list="authorlist" name="author" size="50"/>
  404. <datalist id="authorlist">
  405. <option>---</option>
  406. <option>B. Bieringer</option>
  407. <option>C. Rodenbeck</option>
  408. <option>T. Thuemmler</option>
  409. <option>S. Wuestling</option>
  410. </datalist>
  411. <!--</select>-->
  412. </td>
  413. </tr>
  414. <tr>
  415. <td>comments</td>
  416. <td class="left">
  417. <textarea name="comments" cols="50" rows="5"></textarea>
  418. </td>
  419. </tr>
  420. </table>
  421. <br>
  422. <input type="submit" name="ok" value="submit">
  423. <input type="reset" value="reset">
  424. </form>
  425. </body>
  426. </html>