24 |
24 |
25 require_once('utilities.php'); |
25 require_once('utilities.php'); |
26 |
26 |
27 |
27 |
28 |
28 |
29 function showunit($unit, $unr) |
29 function showunit($unit, $unr, $name) |
30 { |
30 { |
31 global $my_style; |
31 global $my_style; |
32 |
32 |
33 $outstr = ' <!-- showunit(' . $unit . ', ' . $unr . ') -->' . PHP_EOL; |
33 $outstr = ' <!-- showunit(' . $unit . ', ' . $unr . ', ' . $name . ') -->' . PHP_EOL; |
34 $air_state = $beer_state = 1; |
34 $air_state = $beer_state = 1; |
35 $answer = send_cmd("UNIT GET ".$unit); |
35 $answer = send_cmd("UNIT GET ".$unit); |
36 $arr = explode("\r\n", $answer); |
36 $arr = explode("\r\n", $answer); |
37 |
37 |
38 if (startsWith($arr[0], "213")) { |
38 if (startsWith($arr[0], "213")) { |
101 } |
101 } |
102 |
102 |
103 $outstr .= ' <script type="text/javascript">'.PHP_EOL; |
103 $outstr .= ' <script type="text/javascript">'.PHP_EOL; |
104 $outstr .= ' $(document).ready(function () {'.PHP_EOL; |
104 $outstr .= ' $(document).ready(function () {'.PHP_EOL; |
105 |
105 |
|
106 $outstr .= ' function getExportServer'.$unr.'() {'.PHP_EOL; |
|
107 $outstr .= ' return "http://www.jqwidgets.com/export_server/export.php";'.PHP_EOL; |
|
108 $outstr .= ' }'.PHP_EOL; |
106 $outstr .= ' var source'.$unr.' ='.PHP_EOL; |
109 $outstr .= ' var source'.$unr.' ='.PHP_EOL; |
107 $outstr .= ' {'.PHP_EOL; |
110 $outstr .= ' {'.PHP_EOL; |
108 $outstr .= ' datatype: "json",'.PHP_EOL; |
111 $outstr .= ' datatype: "json",'.PHP_EOL; |
109 $outstr .= ' datafields: ['.PHP_EOL; |
112 $outstr .= ' datafields: ['.PHP_EOL; |
110 $outstr .= ' { name: "Date", type: "date", format: "yyyy-MM-ddTHH:mm" },'.PHP_EOL; |
113 $outstr .= ' { name: "Date", type: "date", format: "yyyy-MM-ddTHH:mm" },'.PHP_EOL; |
128 $outstr .= ' loadComplete: function () { },'.PHP_EOL; |
131 $outstr .= ' loadComplete: function () { },'.PHP_EOL; |
129 $outstr .= ' loadError: function () { }'.PHP_EOL; |
132 $outstr .= ' loadError: function () { }'.PHP_EOL; |
130 $outstr .= ' });'.PHP_EOL; |
133 $outstr .= ' });'.PHP_EOL; |
131 |
134 |
132 $outstr .= ' var settings'.$unr.' = {'.PHP_EOL; |
135 $outstr .= ' var settings'.$unr.' = {'.PHP_EOL; |
133 $outstr .= ' title: "Fermentation history",'.PHP_EOL; |
136 $outstr .= ' title: "'.$name.' fermentation history",'.PHP_EOL; |
134 $outstr .= ' description: "",'.PHP_EOL; |
137 $outstr .= ' description: "",'.PHP_EOL; |
135 $outstr .= ' padding: { left: 5, top: 5, right: 5, bottom: 5 },'.PHP_EOL; |
138 $outstr .= ' padding: { left: 5, top: 5, right: 5, bottom: 5 },'.PHP_EOL; |
136 $outstr .= ' titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },'.PHP_EOL; |
139 $outstr .= ' titlePadding: { left: 0, top: 0, right: 0, bottom: 10 },'.PHP_EOL; |
137 $outstr .= ' source: dataAdapter'.$unr.','.PHP_EOL; |
140 $outstr .= ' source: dataAdapter'.$unr.','.PHP_EOL; |
138 $outstr .= ' categoryAxis:'.PHP_EOL; |
141 $outstr .= ' categoryAxis:'.PHP_EOL; |
139 $outstr .= ' {'.PHP_EOL; |
142 $outstr .= ' {'.PHP_EOL; |
140 $outstr .= ' dataField: \'Date\','.PHP_EOL; |
143 $outstr .= ' dataField: \'Date\','.PHP_EOL; |
141 $outstr .= ' textRotationAngle: 45,'.PHP_EOL; |
144 $outstr .= ' textRotationAngle: 45,'.PHP_EOL; |
180 /* Regular updates of the chart */ |
183 /* Regular updates of the chart */ |
181 // $outstr .= ' setInterval(function(){'.PHP_EOL; |
184 // $outstr .= ' setInterval(function(){'.PHP_EOL; |
182 // $outstr .= ' $("#fermentor_chart_'.$unit.'").jqxChart("update");'.PHP_EOL; |
185 // $outstr .= ' $("#fermentor_chart_'.$unit.'").jqxChart("update");'.PHP_EOL; |
183 // $outstr .= ' }, 3000);'.PHP_EOL; |
186 // $outstr .= ' }, 3000);'.PHP_EOL; |
184 |
187 |
|
188 $outstr .= ' $("#print_'.$unr.'").click(function () {'.PHP_EOL; |
|
189 $outstr .= ' var content = $("#fermentor_chart_'.$unit.'")[0].outerHTML;'.PHP_EOL; |
|
190 $outstr .= ' var newWindow = window.open("", "", "width=750, height=400"),'.PHP_EOL; |
|
191 $outstr .= ' document = newWindow.document.open(),'.PHP_EOL; |
|
192 $outstr .= ' pageContent ='.PHP_EOL; |
|
193 $outstr .= ' \'<!DOCTYPE html>\' +'.PHP_EOL; |
|
194 $outstr .= ' \'<html>\' +'.PHP_EOL; |
|
195 $outstr .= ' \'<head>\' +'.PHP_EOL; |
|
196 $outstr .= ' \'<link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />\' +'.PHP_EOL; |
|
197 $outstr .= ' \'<meta charset="utf-8" />\' +'.PHP_EOL; |
|
198 $outstr .= ' \'<title>jQWidgets Chart</title>\' +'.PHP_EOL; |
|
199 $outstr .= ' \'</head>\' +'.PHP_EOL; |
|
200 $outstr .= ' \'<body>\' + content + \'</body></html>\';'.PHP_EOL; |
|
201 $outstr .= ' document.write(pageContent);'.PHP_EOL; |
|
202 $outstr .= ' document.close();'.PHP_EOL; |
|
203 $outstr .= ' newWindow.print();'.PHP_EOL; |
|
204 $outstr .= ' });'.PHP_EOL; |
|
205 $outstr .= ' $("#print_'.$unr.'").jqxButton({ width: 100, height: 25, theme: "ui-redmond" });'.PHP_EOL; |
|
206 |
|
207 $outstr .= ' $("#pngButton_'.$unr.'").click(function () {'.PHP_EOL; |
|
208 // call the export server to create a PNG image |
|
209 $outstr .= ' $("#fermentor_chart_'.$unit.'").jqxChart("saveAsPNG", "Chart_'.$name.'.png", getExportServer'.$unr.'());'.PHP_EOL; |
|
210 $outstr .= ' });'.PHP_EOL; |
|
211 $outstr .= ' $("#pngButton_'.$unr.'").jqxButton({ width: 100, height: 25, theme: "ui-redmond" });'.PHP_EOL; |
|
212 |
185 $outstr .= ' setInterval(function(){'.PHP_EOL; |
213 $outstr .= ' setInterval(function(){'.PHP_EOL; |
186 $outstr .= ' $.getJSON("getstate.php?uuid='.$unit.'", function(data) {'.PHP_EOL; |
214 $outstr .= ' $.getJSON("getstate.php?uuid='.$unit.'", function(data) {'.PHP_EOL; |
187 $outstr .= ' $("#load_air_'.$unr.'").html(data.air_temperature);'.PHP_EOL; |
215 $outstr .= ' $("#load_air_'.$unr.'").html(data.air_temperature);'.PHP_EOL; |
188 $outstr .= ' $("#load_beer_'.$unr.'").html(data.beer_temperature);'.PHP_EOL; |
216 $outstr .= ' $("#load_beer_'.$unr.'").html(data.beer_temperature);'.PHP_EOL; |
189 $outstr .= ' $("#load_target_'.$unr.'").html(data.target_temperature);'.PHP_EOL; |
217 $outstr .= ' $("#load_target_'.$unr.'").html(data.target_temperature);'.PHP_EOL; |
379 $outstr .= ' <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL; |
407 $outstr .= ' <input type="hidden" name="UUID" value="'.$unit.'">'.PHP_EOL; |
380 $outstr .= ' </form>'.PHP_EOL; |
408 $outstr .= ' </form>'.PHP_EOL; |
381 $outstr .= ' </div>'.PHP_EOL; |
409 $outstr .= ' </div>'.PHP_EOL; |
382 $outstr .= ' </div> <!-- fermentor_panel_control -->'.PHP_EOL; |
410 $outstr .= ' </div> <!-- fermentor_panel_control -->'.PHP_EOL; |
383 |
411 |
|
412 $outstr .= ' <div id="fermentor_panel_buttons">'.PHP_EOL; |
|
413 $outstr .= ' <div style="margin-top: 2px; margin-left: 10px;">'.PHP_EOL; |
|
414 $outstr .= ' <input style="float: left;" id="print_'.$unr.'" type="button" value="Print Graph" />'.PHP_EOL; |
|
415 $outstr .= ' <input style="float: left; margin-left: 15px;" id="pngButton_'.$unr.'" type="button" value="Save Graph" />'.PHP_EOL; |
|
416 $outstr .= ' </div>'.PHP_EOL; |
|
417 $outstr .= ' </div> <!-- fermentor_panel_buttons -->'.PHP_EOL; |
|
418 |
384 $outstr .= ' </div> <!-- fermentor -->'.PHP_EOL; |
419 $outstr .= ' </div> <!-- fermentor -->'.PHP_EOL; |
385 } |
420 } |
386 |
421 |
387 return $outstr; |
422 return $outstr; |
388 } |
423 } |
415 $i = 1; |
450 $i = 1; |
416 while (1) { |
451 while (1) { |
417 if (strcmp($arr[$i], ".") == 0) |
452 if (strcmp($arr[$i], ".") == 0) |
418 break; |
453 break; |
419 $parts = explode(",", $arr[$i]); |
454 $parts = explode(",", $arr[$i]); |
420 $outstr .= showunit($parts[0], $i); |
455 $outstr .= showunit($parts[0], $i, $parts[1]); |
421 $i++; |
456 $i++; |
422 } |
457 } |
423 } |
458 } |
424 $outstr .= ' </div> <!-- jqxTabs -->'.PHP_EOL; |
459 $outstr .= ' </div> <!-- jqxTabs -->'.PHP_EOL; |
425 } |
460 } |