Thu, 10 Jan 2019 20:22:06 +0100
Added configuration settings for MQTT in config.php. Finished screen box sizes for the fermenters monitor. Select beername and code from the current brew products and send it to the fermenter. Added switch commands to the fermenter. Delay data get from the fermenter after sending any command so there is time to process the commands. Turn switches off when the mode changes. Removed 0.2 degrees setpoint diffs for low and high, the fermenter must deal with it. Prevent turning the heater and cooler together on.
11 | 1 | <?php |
2 | ||
3 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); | |
4 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); | |
5 | ||
6 | ||
7 | #Connect to the database | |
8 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
9 | if (! $connect) { | |
10 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
11 | } | |
77
a9f8de2d7b2b
Fixed most charset problems. Added fpdf library. Added inventory pdf creation.
Michiel Broek <mbroek@mbse.eu>
parents:
39
diff
changeset
|
12 | mysqli_set_charset($connect, "utf8" ); |
11 | 13 | |
14 | // get data and store in a json array | |
37
9362eb9e9e5b
Sorting the inventory and changes some grid tables.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
15 | $query = "SELECT * FROM inventory_fermentables ORDER BY supplier,name"; |
11 | 16 | if (isset($_GET['insert'])) { |
17 | // INSERT COMMAND | |
18 | $sql = "INSERT INTO `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
19 | $sql .= "', type='" . $_GET['type']; | |
20 | $sql .= "', yield='" . $_GET['yield']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
21 | $sql .= "', color='" . $_GET['color']; |
11 | 22 | ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; |
23 | $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); | |
24 | $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); | |
25 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
26 | $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; | |
27 | $sql .= "', moisture='" . $_GET['moisture']; | |
28 | $sql .= "', diastatic_power='" . $_GET['diastatic_power']; | |
29 | $sql .= "', protein='" . $_GET['protein']; | |
30 | $sql .= "', max_in_batch='" . $_GET['max_in_batch']; | |
31 | ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; | |
32 | $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; | |
33 | ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; | |
34 | $sql .= "', di_ph='" . $_GET['di_ph']; | |
35 | $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; | |
36 | $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); | |
37 | $sql .= "', inventory='" . $_GET['inventory']; | |
38 | $sql .= "', cost='" . $_GET['cost']; | |
39 | $sql .= "', production_date='" . $_GET['production_date']; | |
40 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
41 | //$sql .= "', supplier_rec='" . $_GET['supplier_rec']; |
11 | 42 | $sql .= "';"; |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
43 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
44 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
45 | syslog(LOG_NOTICE, "db_inventory_fermentables: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
46 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
47 | syslog(LOG_NOTICE, "db_inventory_fermentables: inserted ".$_GET['name']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
48 | } |
11 | 49 | echo $result; |
50 | ||
51 | } else if (isset($_GET['update'])) { | |
52 | // UPDATE COMMAND | |
53 | $sql = "UPDATE `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
54 | $sql .= "', type='" . $_GET['type']; | |
55 | $sql .= "', yield='" . $_GET['yield']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
56 | $sql .= "', color='" . $_GET['color']; |
11 | 57 | ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; |
58 | $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); | |
59 | $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); | |
60 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
61 | $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; | |
62 | $sql .= "', moisture='" . $_GET['moisture']; | |
63 | $sql .= "', diastatic_power='" . $_GET['diastatic_power']; | |
64 | $sql .= "', protein='" . $_GET['protein']; | |
65 | $sql .= "', max_in_batch='" . $_GET['max_in_batch']; | |
66 | ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; | |
67 | $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; | |
68 | ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; | |
69 | $sql .= "', di_ph='" . $_GET['di_ph']; | |
70 | $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; | |
71 | $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); | |
72 | $sql .= "', inventory='" . $_GET['inventory']; | |
73 | $sql .= "', cost='" . $_GET['cost']; | |
74 | $sql .= "', production_date='" . $_GET['production_date']; | |
75 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
76 | //$sql .= "', supplier_rec='" . $_GET['supplier_rec']; |
11 | 77 | $sql .= "' WHERE record='" . $_GET['record'] . "';"; |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
78 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
79 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
80 | syslog(LOG_NOTICE, "db_inventory_fermentables: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
81 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
82 | syslog(LOG_NOTICE, "db_inventory_fermentables: updated record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
83 | } |
11 | 84 | echo $result; |
85 | ||
86 | } else if (isset($_GET['delete'])) { | |
87 | // DELETE COMMAND | |
88 | $sql = "DELETE FROM `inventory_fermentables` WHERE record='".$_GET['record']."';"; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
89 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
90 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
91 | syslog(LOG_NOTICE, "db_inventory_fermentables: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
92 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
93 | syslog(LOG_NOTICE, "db_inventory_fermentables: deleted record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
11
diff
changeset
|
94 | } |
11 | 95 | echo $result; |
96 | ||
97 | } else { | |
98 | // SELECT COMMAND | |
99 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); | |
100 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
101 | $fermentables[] = array( | |
102 | 'record' => $row['record'], | |
103 | 'name' => $row['name'], | |
104 | 'type' => $row['type'], | |
105 | 'yield' => $row['yield'], | |
106 | 'color' => $row['color'], | |
107 | 'add_after_boil' => $row['add_after_boil'], | |
108 | 'origin' => $row['origin'], | |
109 | 'supplier' => $row['supplier'], | |
110 | 'notes' => $row['notes'], | |
111 | 'coarse_fine_diff' => $row['coarse_fine_diff'], | |
112 | 'moisture' => $row['moisture'], | |
113 | 'diastatic_power' => $row['diastatic_power'], | |
114 | 'protein' => $row['protein'], | |
115 | 'max_in_batch' => $row['max_in_batch'], | |
116 | 'recommend_mash' => $row['recommend_mash'], | |
117 | 'ibu_gal_per_lb' => $row['ibu_gal_per_lb'], | |
118 | 'always_on_stock' => $row['always_on_stock'], | |
119 | 'di_ph' => $row['di_ph'], | |
120 | 'acid_to_ph_57' => $row['acid_to_ph_57'], | |
121 | 'graintype' => $row['graintype'], | |
122 | 'inventory' => $row['inventory'], | |
123 | 'cost' => $row['cost'], | |
124 | 'production_date' => $row['production_date'], | |
39 | 125 | 'tht_date' => $row['tht_date'] |
11 | 126 | ); |
127 | } | |
128 | echo json_encode($fermentables); | |
129 | } | |
130 | ?> |