index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. <<<<<<< HEAD
  233. <img style="margin-right: .5em; margin-bottom: -8px" src="../pics/katrin_logo_round.png" width="40px" height="40px">
  234. =======
  235. <img style="margin-right: 1em; padding: 5px" src="../pics/katrin_logo_round.png" width="2em" height="2em">
  236. >>>>>>> 8d26f27 (Patchpanel styling)
  237. <a>
  238. <b>High-Voltage Patch-Panel Configuration</b>
  239. </font>
  240. <br><br>
  241. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  242. <tr>
  243. <td><b>configuration</b></td>
  244. <td>
  245. <select name="configurationload" size="1" onchange="myform.submit();">
  246. <option>(active configuration)</option>
  247. <?php
  248. if ($_POST["configurationload"] == "(new configuration)") echo '<option selected>'; else echo '<option>';
  249. echo '(new configuration)</option>';
  250. foreach (glob("data/*.conf") as $filename)
  251. {
  252. $buffer = substr($filename, 5, strlen($filename) - 10);
  253. if ($_POST["configurationload"] == $buffer) echo '<option selected>'; else echo '<option>';
  254. echo $buffer . '</option>';
  255. }
  256. ?>
  257. </select>
  258. </td>
  259. </tr>
  260. <tr>
  261. <td>name</td>
  262. <td>
  263. <input type="text" name="configurationname" size="35">
  264. </td>
  265. </tr>
  266. </table>
  267. <br>
  268. <table border="0" cellpadding="0" cellspacing="0">
  269. <tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>
  270. <tr>
  271. <th bgcolor="#C8C8C8" colspan="22"><b>W E S T</b></th>
  272. <th colspan="3"><b>PATCH PANEL</b></th>
  273. <th bgcolor="#C8C8C8" colspan="22"><b>E A S T</b></th>
  274. </tr>
  275. <tr>
  276. <?php
  277. for ($id=2; $id<7; $id++) {
  278. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  279. echo '<td class="highlight ' . $class . '" colspan="2">0' . $id . '</td>';
  280. }
  281. echo '<td colspan="2">07-11</td>';
  282. for ($id=12; $id<17; $id++) {
  283. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  284. echo '<td class="highlight ' . $class . '" colspan="2">' . $id . '</td>';
  285. }
  286. echo '<td>&nbsp;ADEI&nbsp;</td>';
  287. echo '<td>&nbsp;CH&nbsp;</td>';
  288. echo '<td>&nbsp;ADEI&nbsp;</td>';
  289. for ($id=2; $id<7; $id++) {
  290. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  291. echo '<td class="highlight ' . $class . '" colspan="2">0' . $id . '</td>';
  292. }
  293. echo '<td colspan="2">07-11</td>';
  294. for ($id=12; $id<17; $id++) {
  295. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  296. echo '<td class="highlight ' . $class . '" colspan="2">' . $id . '</td>';
  297. }
  298. ?>
  299. </tr>
  300. <tr>
  301. <?php
  302. for ($id=0; $id<11; $id++) {
  303. if ($id % 2 == 1) $class = "odd"; else $class = "even";
  304. echo '<td class="highlight ' . $class . '">o</td><td class="highlight ' . $class . '">i</td>';
  305. }
  306. echo '<td></td>';
  307. echo '<td></td>';
  308. echo '<td></td>';
  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. ?>
  314. </tr>
  315. <?php
  316. for ($ch=0; $ch<23; $ch++)
  317. {
  318. if ($ch % 5 == 0) echo '<tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>';
  319. $text = str_pad($ch, 2, 0, STR_PAD_LEFT);
  320. echo '<tr class="highlight">';
  321. for ($id=0; $id<22; $id++)
  322. {
  323. //if ($id % 4 == 2 || $id % 4 == 3) $color = "#FFFFFF"; else $color = "#C8C8C8";
  324. if ($id % 4 == 2 || $id % 4 == 3) $class = "odd"; else $class = "even";
  325. $checked = "";
  326. if ($check[$id] == $ch) $checked = 'checked="checked"';
  327. echo '<td class="highlight ' . $class . '"><label class="container"><input type="radio" name="' . $rings[$id] . '" value="' . $ch . '" ' . $checked . '><span class="checkmark"></span></label></td>';
  328. }
  329. $value = $adeiValue[1][$ch];
  330. if ($ch == 22) $value = $adeiValue[0][0] + $adeiValue[0][1];
  331. echo '<td>' . sprintf('%.0F', $value) . '</td>';
  332. echo '<th><b>';
  333. if ($ch == 22) echo 'IE';
  334. else echo $text;
  335. echo '</b></th>';
  336. $value = $adeiValue[2][$ch];
  337. if ($ch == 22) $value = $adeiValue[0][0] + $adeiValue[0][2];
  338. echo '<td>' . sprintf('%.0F', $value) . '</td>';
  339. for ($id=22; $id<44; $id++)
  340. {
  341. //if ($id % 4 == 0 || $id % 4 == 1) $color = "#FFFFFF"; else $color = "#C8C8C8";
  342. if ($id % 4 == 2 || $id % 4 == 3) $class = "even"; else $class = "odd";
  343. $checked = "";
  344. if ($check[$id] == $ch) $checked = 'checked="checked"';
  345. echo '<td class="highlight ' . $class . '"><label class="container"><input type="radio" name="' . $rings[$id] . '" value="' . $ch . '" ' . $checked . '><span class="checkmark"></span></label></td>';
  346. }
  347. echo '</tr>';
  348. }
  349. ?>
  350. <tr bgcolor="#000000" height="1px"><td colspan="47"></td></tr>
  351. </table>
  352. <br>
  353. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  354. <tr>
  355. <td><b>valid from</b></td>
  356. <td>
  357. <!-- <input type="text" name="validfrom" size="19" maxlength="19"> (YYYY-MM-DD HH:MM:SS) -->
  358. <input type="date" name="validfrom-date">
  359. <input type="time" name="validfrom-time">
  360. </td>
  361. </tr>
  362. </table>
  363. <br>
  364. <table border="0" cellpadding="5" cellspacing="0" bgcolor="#C8C8C8">
  365. <tr>
  366. <td width="200px"><b>elog entry</b></td>
  367. <td class="left">
  368. <input type="checkbox" name="elog" value="yes"> submit to ELOG
  369. </td>
  370. </tr>
  371. <tr>
  372. <td><b>database entry</b></td>
  373. <td class="left">
  374. <input type="checkbox" name="database" value="yes"> submit to KDB
  375. </td>
  376. </tr>
  377. <tr>
  378. <td>author<br/><sup>(click twice to open drop-down)</sup></td>
  379. <td class="left">
  380. <!--<select name="author" size="1">-->
  381. <input type="text" list="authorlist" name="author" size="50"/>
  382. <datalist id="authorlist">
  383. <option>---</option>
  384. <option>B. Bieringer</option>
  385. <option>C. Rodenbeck</option>
  386. <option>T. Thuemmler</option>
  387. <option>S. Wuestling</option>
  388. </datalist>
  389. <!--</select>-->
  390. </td>
  391. </tr>
  392. <tr>
  393. <td>comments</td>
  394. <td class="left">
  395. <textarea name="comments" cols="50" rows="5"></textarea>
  396. </td>
  397. </tr>
  398. </table>
  399. <br>
  400. <input type="submit" name="ok" value="submit">
  401. <input type="reset" value="reset">
  402. </form>
  403. </body>
  404. </html>