www/includes/global.inc.php

changeset 676
09b5efe0c633
parent 675
825210ba2707
child 678
cc49115e769e
equal deleted inserted replaced
675:825210ba2707 676:09b5efe0c633
22 *****************************************************************************/ 22 *****************************************************************************/
23 23
24 /* 24 /*
25 * Look for the style names in the jqwidgets/styles directory. 25 * Look for the style names in the jqwidgets/styles directory.
26 */ 26 */
27 $my_style = 'ui-redmond'; 27 //$my_style = 'ui-redmond';
28 //$my_style = 'ui-mbse'; 28 $my_style = 'ui-mbse';
29 29
30 require_once($_SERVER['DOCUMENT_ROOT'].'/version.php'); 30 require_once($_SERVER['DOCUMENT_ROOT'].'/version.php');
31
32
33 function open_socket()
34 {
35 $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
36
37 if (!($sock === false)) {
38 if (socket_connect($sock, "localhost", 6554)) {
39 socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0));
40 } else {
41 socket_close($sock);
42 }
43 }
44 return $sock;
45 }
46
47
48 /**
49 * @param string $command to send to the server.
50 * @return string with the complete reply from the
51 * server. This can be a multiline reply.
52 */
53 function send_cmd($command)
54 {
55 $sock = open_socket();
56 if ($sock == false) {
57 return "";
58 }
59 socket_write($sock, $command . "\r\n", 4096);
60
61 $answer = "";
62 while (1) {
63 $line = socket_read($sock, 4096);
64 if ($line === '')
65 break;
66 $answer .= $line;
67 }
68 socket_close($sock);
69
70 return $answer;
71 }
72
73
74 function startsWith($haystack, $needle)
75 {
76 return !strncmp($haystack, $needle, strlen($needle));
77 }
31 78
32 79
33 function page_header($title, $loadjs) { 80 function page_header($title, $loadjs) {
34 global $my_style; 81 global $my_style;
35 global $my_version; 82 global $my_version;
36 ?> 83 ?>
37 <!DOCTYPE html> 84 <!DOCTYPE html>
38 <html lang=en-US> 85 <html>
39 <head> 86 <head>
40 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 87 <meta charset="utf-8">
41 <title>ThermFerm v<?php echo $my_version;?> - <?php echo $title;?></title> 88 <title>ThermFerm v<?php echo $my_version;?> - <?php echo $title;?></title>
42 <!-- <link type="text/css" href="css/style.css" rel="stylesheet" media="all" /> --> 89 <link type="text/css" href="css/style.css" rel="stylesheet" media="all" />
43 <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" /> 90 <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" />
44 <link type="text/css" href="jqwidgets/styles/jqx.<?php echo $my_style; ?>.css" rel="stylesheet" /> 91 <link type="text/css" href="jqwidgets/styles/jqx.<?php echo $my_style; ?>.css" rel="stylesheet" />
45 <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 92 <meta name="viewport" content="width=device-width, initial-scale=1">
46 <script> 93 <script>
47 var theme = "<?php echo $my_style; ?>"; 94 var theme = "<?php echo $my_style; ?>";
48 </script> 95 </script>
49 <script src="js/jquery-1.11.1.js"></script> 96 <script src="js/jquery-1.11.1.js"></script>
50 <script src="js/reconnecting-websocket.min.js"></script> 97 <script src="js/reconnecting-websocket.min.js"></script>
70 117
71 <!-- Menu --> 118 <!-- Menu -->
72 <div id="jqxMenu" style='float: left;'> 119 <div id="jqxMenu" style='float: left;'>
73 <ul> 120 <ul>
74 <li style='width: 80px;'><a href="index.php">Home</a></li> 121 <li style='width: 80px;'><a href="index.php">Home</a></li>
122 <li style='width: 80px;'>Fermenters
123 <ul style='width: 200px;'>
124 <?php
125 $answer = send_cmd("LIST");
126 if (strlen($answer)) {
127 $arr = explode("\r\n", $answer);
128
129 if (startsWith($arr[0], "212")) {
130 $i = 1;
131 while (1) {
132 if (strcmp($arr[$i], ".") == 0)
133 break;
134 $parts = explode(",", $arr[$i]);
135 echo ' <li><img style="float: left; margin-right: 5px;" src="images/fridge.png" />';
136 echo '<a href="fermenter.php?uuid='.$parts[0].'">'.$parts[1].'</a></li>'.PHP_EOL;
137 $i++;
138 }
139 }
140 }
141 ?>
142 </ul>
143 </li>
75 <li style='width: 80px;'>Setup 144 <li style='width: 80px;'>Setup
76 <ul style='width: 200px;'> 145 <ul style='width: 200px;'>
77 <li><img style='float: left; margin-right: 5px;' src='images/preferences.png' /><a href="set_global.php">Global</a></li> 146 <li><img style='float: left; margin-right: 5px;' src='images/preferences.png' /><a href="set_global.php">Global</a></li>
78 <li><img style='float: left; margin-right: 5px;' src='images/database.png' /><a href="set_devices.php">Devices</a></li> 147 <li><img style='float: left; margin-right: 5px;' src='images/database.png' /><a href="set_devices.php">Devices</a></li>
79 <li><img style='float: left; margin-right: 5px;' src='images/fermenter.png' /><a href="set_fermenters.php">Fermenters</a></li> 148 <li><img style='float: left; margin-right: 5px;' src='images/fermenter.png' /><a href="set_fermenters.php">Fermenters</a></li>
80 <li><img style='float: left; margin-right: 5px;' src='images/computer.png' /><a href="set_simulators.php">Simulators</a></li> 149 <li><img style='float: left; margin-right: 5px;' src='images/computer.png' /><a href="set_simulators.php">Simulators</a></li>
81 </ul> 150 </ul>
151 </li>
82 <li style='width: 80px;'><a href="gen_about.php">Over</a></li> 152 <li style='width: 80px;'><a href="gen_about.php">Over</a></li>
83 </ul> 153 </ul>
84 </div> <!-- End menu --> 154 </div> <!-- End menu -->
85 155
86 <?php 156 <?php

mercurial