Sun, 12 May 2019 19:24:34 +0200
Version 0.2.0 merged with default.
99
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | <?php |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | #Connect to the database |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | if (! $connect) { |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | } |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | mysqli_set_charset($connect, "utf8" ); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | $escapers = array("\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | $replacements = array("\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | $query = "SELECT * FROM profile_setup WHERE record='1'"; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | if (isset($_POST['update'])) { |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | /* Search water record */ |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | $result = mysqli_query($connect, "SELECT record FROM inventory_waters WHERE name='".$_POST['default_water']."';"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | $default_water = $row['record']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | else |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | $default_water = 0; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | $sql = "UPDATE `profile_setup` SET "; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | $sql .= "brewery_name='" . mysqli_real_escape_string($connect, $_POST['brewery_name']); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | $sql .= "', factor_mashhop='" . $_POST['factor_mashhop']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | $sql .= "', factor_fwh='" . $_POST['factor_fwh']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | $sql .= "', factor_pellet='" . $_POST['factor_pellet']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | $sql .= "', factor_plug='" . $_POST['factor_plug']; |
289
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
30 | $sql .= "', factor_wethop='" . $_POST['factor_wethop']; |
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
31 | $sql .= "', color_method='" . $_POST['color_method']; |
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
32 | $sql .= "', ibu_method='" . $_POST['ibu_method']; |
99
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | $sql .= "', brix_correction='" . $_POST['brix_correction']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | $sql .= "', grain_absorbtion='" . $_POST['grain_absorbtion']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | $sql .= "', default_water='" . $default_water; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | $sql .= "' WHERE record='1';"; |
289
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
37 | //syslog(LOG_NOTICE, $sql); |
99
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | $result = mysqli_query($connect, $sql); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | if (! $result) { |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | syslog(LOG_NOTICE, "db_profile_setup: ".$sql." result: ".mysqli_error($connect)); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | } else { |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | syslog(LOG_NOTICE, "db_profile_setup: updated record 1"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | } |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | echo $result; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
45 | } else { |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
46 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | /* search water name */ |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | $wresult = mysqli_query($connect, "SELECT name FROM inventory_waters WHERE record='".$row['default_water']."';"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | if ($wrow = mysqli_fetch_array($wresult, MYSQLI_ASSOC)) |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | $default_water = $wrow['name']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
52 | else |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
53 | $default_water = ''; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
54 | $data = '{"record":' . $row['record']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
55 | $data .= ',"brewery_name":"' . str_replace($escapers, $replacements, $row['brewery_name']); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
56 | $data .= '","factor_mashhop":' . $row['factor_mashhop']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
57 | $data .= ',"factor_fwh":' . $row['factor_fwh']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
58 | $data .= ',"factor_pellet":' . $row['factor_pellet']; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | $data .= ',"factor_plug":' . $row['factor_plug']; |
289
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
60 | $data .= ',"factor_wethop":' . $row['factor_wethop']; |
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
61 | $data .= ',"ibu_method":' . $row['ibu_method']; |
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
62 | $data .= ',"color_method":' . $row['color_method']; |
4082c41f45e9
Added the use and calculation of wet hops. Assume 5.5 times more hops needed by weight.
Michiel Broek <mbroek@mbse.eu>
parents:
99
diff
changeset
|
63 | $data .= ',"brix_correction":' . floatval($row['brix_correction']); |
99
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
64 | $data .= ',"grain_absorbtion":' . floatval($row['grain_absorbtion']); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | $data .= ',"default_water":"' . str_replace($escapers, $replacements, $default_water); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | $data .= '"}'; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | } |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | header("Content-type: application/json"); |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | echo $data; |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | } |
f433193f7bb6
Removed default water setting from the inventory_waters table. Added global setup record with default settings and the default water selection. Added a setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | ?> |