PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/webfrontend/pgm4/fs20.php

https://github.com/frankyH/fhem-mirror
PHP | 240 lines | 204 code | 32 blank | 4 comment | 25 complexity | 8ee6e186724c06752f8fff680744234f MD5 | raw file
Possible License(s): GPL-2.0
  1. <HTML>
  2. <HEAD>
  3. </HEAD>
  4. <BODY>
  5. <TITLE>
  6. FS 20 Haussteuerrung
  7. </TITLE>
  8. </BODY>
  9. <?PHP
  10. function is_posint($a) {
  11. return (((string)$a === (string)(int)$a) && ((int)$a >= 0));
  12. }
  13. function print_options($name, $device, $dimmable, $href)
  14. {
  15. echo "<A href=\"fs20.php?device=$device&state=toggle&command=set\">";
  16. echo "$name</A>";
  17. echo "<FORM action=\"fs20.php\">";
  18. echo "<SELECT size=1 name=\"state\">";
  19. echo "<OPTION value=\"off\" selected>Off";
  20. if ( $dimmable ) {
  21. echo "<OPTION value=\"dimup\">Up";
  22. echo "<OPTION value=\"dimdown\">Down";
  23. echo "<OPTION value=\"dim06%\">6%";
  24. echo "<OPTION value=\"dim12%\">12%";
  25. echo "<OPTION value=\"dim18%\">18%";
  26. echo "<OPTION value=\"dim25%\">25%";
  27. echo "<OPTION value=\"dim31%\">31%";
  28. echo "<OPTION value=\"dim37%\">37%";
  29. echo "<OPTION value=\"dim43%\">43%";
  30. echo "<OPTION value=\"dim50%\">50%";
  31. echo "<OPTION value=\"dim56%\">56%";
  32. echo "<OPTION value=\"dim62%\">62%";
  33. echo "<OPTION value=\"dim68%\">68%";
  34. echo "<OPTION value=\"dim75%\">75%";
  35. echo "<OPTION value=\"dim81%\">81%";
  36. echo "<OPTION value=\"dim87%\">87%";
  37. echo "<OPTION value=\"dim93%\">93%";
  38. }
  39. echo "<OPTION value=\"dim100%\">100%";
  40. echo "</SELECT>";
  41. echo "<INPUT type=\"hidden\" name=\"device\" value=\"$device\">";
  42. echo "<INPUT type=\"hidden\" name=\"command\" value=\"set\">";
  43. echo "<BR>";
  44. echo "<INPUT type=\"submit\" name=\"dim\" value=\"Dim\">";
  45. echo "</FORM>";
  46. }
  47. function generate_random()
  48. {
  49. $devices=array("dg.gang", "dg.wand", "dg.dusche", "dg.bad", "dg.reduit", "dg.eltern", "dg.kino", "og.gang", "og.bad.links", "og.bad.rechts", "og.bad.sterne", "og.bad.decke", "og.stefan.decke", "og.stefan.pult", "og.sandra.decke", "og.kind.r", "og.kind.l", "eg.sitzplatz", "eg.wohnzimmer", "eg.bar", "eg.tisch", "eg.decke", "eg.kueche", "eg.bahnlicht", "eg.bad", "eg.gang", "eg.og.treppe", "ug.gast", "ug.gast.dose", "ug.aussen", "ug.gang", "ug.eg.treppe");
  50. #number of events (min - max)
  51. $event_min=isset($_GET['event_min']) ? $_GET['event_min'] : 5;
  52. $event_max=isset($_GET['event_max']) ? $_GET['event_max'] : 20;
  53. #maximum delay in minutes
  54. $delay_min=isset($_GET['delay_min']) ? $_GET['delay_min'] : 0;
  55. $delay_max=isset($_GET['delay_max']) ? $_GET['delay_max'] : 240;
  56. #minimum and maximum ontime in minutes
  57. $ontime_min=isset($_GET['ontime_min']) ? $_GET['ontime_min'] : 5;
  58. $ontime_max=isset($_GET['ontime_max']) ? $_GET['ontime_max'] : 60;
  59. $variant=isset($_GET['variant']) ? $_GET['variant'] : "onoff";
  60. echo "<H2>Random event generator (\"holiday-function\")</H2>";
  61. echo "<FORM action=\"fs20.php\">";
  62. echo "<TABLE>";
  63. echo "<TR><TD>Number of events:</TD><TD><INPUT type=\"text\" size=\"3\" name=\"event_min\" value=\"$event_min\">-";
  64. echo "<INPUT type=\"text\" size=\"3\" name=\"event_max\" value=\"$event_max\">";
  65. if ( $event_min > $event_max ) { echo " : <FONT color=\"red\">min has to be <= max</FONT>"; unset($_GET['random']); }
  66. if ( !is_posint($event_min)) { echo " : <FONT color=\"red\">min has to be a integer</FONT>"; unset($_GET['random']); }
  67. if ( !is_posint($event_max)) { echo " : <FONT color=\"red\">max has to be a integer</FONT>"; unset($_GET['random']); }
  68. echo "</TD></TR>";
  69. echo "<TR><TD>Delay from now:</TD><TD><INPUT type=\"text\" size=\"3\" name=\"delay_min\" value=\"$delay_min\">-";
  70. echo "<INPUT type=\"text\" size=\"3\" name=\"delay_max\" value=\"$delay_max\">Min.";
  71. if ( $delay_min > $delay_max ) { echo " : <FONT color=\"red\">min has to be <= max</FONT>"; unset($_GET['random']); }
  72. if ( !is_posint($delay_min)) { echo " : <FONT color=\"red\">min has to be a integer</FONT>"; unset($_GET['random']); }
  73. if ( !is_posint($delay_max)) { echo " : <FONT color=\"red\">max has to be a integer</FONT>"; unset($_GET['random']); }
  74. echo "</TD></TR>";
  75. echo "<TR><TD>Time to keep on:</TD><TD><INPUT type=\"text\" size=\"3\" name=\"ontime_min\" value=\"$ontime_min\">-";
  76. echo "<INPUT type=\"text\" size=\"3\" name=\"ontime_max\" value=\"$ontime_max\">Min.";
  77. if ( $ontime_min > $ontime_max ) { echo " : <FONT color=\"red\">min has to be <= max</FONT>"; unset($_GET['random']); }
  78. if ( !is_posint($ontime_min)) { echo " : <FONT color=\"red\">min has to be a integer</FONT>"; unset($_GET['random']); }
  79. if ( !is_posint($ontime_max)) { echo " : <FONT color=\"red\">max has to be a integer</FONT>"; unset($_GET['random']); }
  80. echo "</TD></TR>";
  81. echo "<TR><TD colspan=\"2\">Varant: <SELECT size=1 name=\"variant\">";
  82. echo "<OPTION value=\"onoff\"";
  83. printf("%s", $variant == "onoff" ? " selected" : "");
  84. echo ">on / off";
  85. echo "<OPTION value=\"oft\"";
  86. printf("%s", $variant == "oft" ? " selected" : "");
  87. echo ">on-for-timer";
  88. echo "</SELECT>";
  89. echo "<INPUT type=\"submit\" name=\"random\" value=\"Generate!\">";
  90. echo "</TD></TR></TABLE>";
  91. echo "</FORM><P>";
  92. if ( isset($_GET['random'])) {
  93. $event=rand($event_min, $event_max);
  94. echo "Just copy lines below into FHZ1000 command window";
  95. echo "<pre>";
  96. for($i=0; $i<$event; $i++) {
  97. $starttime=rand($delay_min, $delay_max);
  98. $hour=intval($starttime/60);
  99. $minute=intval($starttime%60);
  100. $second=rand(0,59);
  101. $ontime=rand($ontime_min, $ontime_max);
  102. $dev=$devices[array_rand($devices)];
  103. if ($variant == "oft") {
  104. printf("at +%02d:%02d:%02d set %s on-for-timer %d<br>", $hour, $minute, $second, $dev, $ontime);
  105. } elseif ($variant == "onoff") {
  106. $offtime=$starttime + $ontime;
  107. $hour_off=intval($offtime / 60);
  108. $minute_off=intval($offtime % 60);
  109. $second_off=rand(0,59);
  110. printf("at +%02d:%02d:%02d set %s on<br>", $hour, $minute, $second, $dev);
  111. printf("at +%02d:%02d:%02d set %s off<br>", $hour_off, $minute_off, $second_off, $dev);
  112. }
  113. }
  114. echo "<pre>";
  115. }
  116. }
  117. ?>
  118. <H1>
  119. FS 20 Haussteuerrung
  120. </H1>
  121. Quicklinks:
  122. <A HREF="#EG">EG</A>
  123. <A HREF="#GE">Generic</A>
  124. <A HREF="#RA">Random</A>
  125. <HR>
  126. <A name="EG">
  127. <H2>EG</H2>
  128. </A>
  129. <TABLE background=images/EG.gif width=567 height=589 border=0>
  130. <TR height=100 align=center><TD width=55></TD><TD width=70></TD><TD width=25></TD><TD width=100></TD><TD width=60></TD><TD width=25></TD><TD width=70></TD><TD width=25></TD><TD width=70></TD><TD></TD></TR>
  131. <TR height=120 align=center><TD></TD><TD colspan=2>
  132. <?PHP print_options("BAR", "eg.bar", TRUE, "EG"); ?>
  133. </TD><TD></TD><TD colspan=4>
  134. <?PHP print_options("WOHNZIMMER", "eg.wohnzimmer", TRUE, "EG"); ?>
  135. </TD><TD></TD><TD></TD></TR>
  136. <TR height=20></TR>
  137. <TR height=70 align=center><TD></TD><TD>
  138. <?PHP print_options("BAD", "eg.bad", FALSE, "EG"); ?>
  139. </TD><TD></TD><TD colspan=2>
  140. <?PHP print_options("GANG", "eg.gang", TRUE, "EG"); ?>
  141. </TD><TD></TD><TD>
  142. <?PHP print_options("TREPPE", "eg.og.treppe", FALSE, "EG"); ?>
  143. </TD><TD></TD><TD></TD><TD></TD></TR>
  144. <TR height=20></TR>
  145. <TR height=70 align=center><TD></TD><TD colspan=2>
  146. <?PHP print_options("KUECHE", "eg.kueche", TRUE, "EG"); ?>
  147. </TD><TD></TD><TD colspan=3>
  148. <?PHP print_options("ESSTISCH", "eg.tisch", TRUE, "EG"); ?>
  149. </TD><TD></TD><TD>
  150. <?PHP print_options("BAHNLICHT", "eg.bahnlicht", FALSE, "EG"); ?>
  151. </TD><TD></TD></TR>
  152. <TR height=20 align=center></TR>
  153. <TR height=70 align=center><TD></TD><TD></TD><TD></TD><TD></TD><TD colspan=3>
  154. <?PHP print_options("DECKE", "eg.decke", FALSE, "EG"); ?>
  155. </TD><TD></TD><TD>
  156. <?PHP print_options("SITZPLATZ", "eg.sitzplatz", FALSE, "EG"); ?>
  157. </TD><TD></TD></TR>
  158. <TR></TR>
  159. </TABLE>
  160. <HR>
  161. <A name="GE">
  162. <H2>Send generic command:</H2>
  163. <FORM action="fs20.php">
  164. <?PHP
  165. echo "<INPUT type=\"textarea\" cols=\"80\" rows=\"5\" name=\"generic\"";
  166. printf("value=\"%s\">", isset($_GET['generic']) ? $_GET['generic'] : "");
  167. ?>
  168. <INPUT type="submit" name="submit" value="send">
  169. </FORM>
  170. <HR>
  171. <A name="RA">
  172. <?PHP
  173. generate_random();
  174. //execute command
  175. unset($cmdline);
  176. if (isset($_GET['generic'])) {
  177. $cmdline=explode("\n", $_GET['generic']);
  178. } elseif (isset($_GET['device']) && isset($_GET['state']) && isset($_GET['command'])) {
  179. $cmdline=array($_GET['command']." ".$_GET['device']." ".$_GET['state']);
  180. }
  181. if (isset($cmdline)) {
  182. array_push($cmdline, "quit");
  183. echo "<HR><H2>Last command</H2>";
  184. echo "<TABLE><TR valign=top><TD>send:</TD><TD>";
  185. foreach($cmdline as $line) {
  186. echo "$line<br>";
  187. }
  188. echo "</TD></TR></TABLE>";
  189. echo "<H3><Output></H3>";
  190. $fp = fsockopen("localhost", 7072, $errno, $errstr, 10);
  191. if (!$fp) {
  192. echo "$errstr ($errno)<br>\n";
  193. } else {
  194. foreach($cmdline as $line) {
  195. fwrite($fp, $line."\n");
  196. }
  197. echo "<pre>";
  198. while (!feof($fp)) {
  199. echo htmlentities(fgets($fp));
  200. }
  201. echo "</pre>";
  202. fclose($fp);
  203. }
  204. echo "<HR>";
  205. }
  206. ?>
  207. </BODY>
  208. </HTML>