Mon, 17 Dec 2018 22:24:32 +0100
Added several sparge_ fields in the recipes databases. Added basic water mix calculator. Added fields on the water tab for water calculations.
27 | 1 | <?php |
2 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); | |
3 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); | |
4 | ||
5 | #Connect to the database | |
6 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
7 | if (! $connect) { | |
8 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
9 | } | |
77
a9f8de2d7b2b
Fixed most charset problems. Added fpdf library. Added inventory pdf creation.
Michiel Broek <mbroek@mbse.eu>
parents:
37
diff
changeset
|
10 | mysqli_set_charset($connect, "utf8" ); |
27 | 11 | |
12 | // get data and store in a json array | |
37
9362eb9e9e5b
Sorting the inventory and changes some grid tables.
Michiel Broek <mbroek@mbse.eu>
parents:
27
diff
changeset
|
13 | $query = "SELECT * FROM inventory_equipments ORDER BY name"; |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
14 | if (isset($_GET['insert']) || isset($_GET['update'])) { |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
15 | if (isset($_GET['insert'])) { |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
16 | // INSERT COMMAND |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
17 | $sql = "INSERT INTO `inventory_equipments` SET "; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
18 | } |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
19 | if (isset($_GET['update'])) { |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
20 | // UPDATE COMMAND |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
21 | $sql = "UPDATE `inventory_equipments` SET "; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
22 | } |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
23 | $sql .= "name='" . mysqli_real_escape_string($connect, $_GET['name']); |
27 | 24 | $sql .= "', boil_size='" . $_GET['boil_size']; |
116
ac993ef43b13
Removed all calculations from the equipemnts database script and added missing fields. Added missing fields to the inventory equipemnts edit screen. Added conditional batch size calculation to the equipments editor. Added specific heat settings to the equipments editor.
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
25 | $sql .= "', batch_size='" . $_GET['batch_size']; |
27 | 26 | $sql .= "', tun_volume='" . $_GET['tun_volume']; |
27 | $sql .= "', tun_weight='" . $_GET['tun_weight']; | |
116
ac993ef43b13
Removed all calculations from the equipemnts database script and added missing fields. Added missing fields to the inventory equipemnts edit screen. Added conditional batch size calculation to the equipments editor. Added specific heat settings to the equipments editor.
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
28 | $sql .= "', tun_specific_heat='" . $_GET['tun_specific_heat']; |
ac993ef43b13
Removed all calculations from the equipemnts database script and added missing fields. Added missing fields to the inventory equipemnts edit screen. Added conditional batch size calculation to the equipments editor. Added specific heat settings to the equipments editor.
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
29 | $sql .= "', tun_material='" . mysqli_real_escape_string($connect, $_GET['tun_material']); |
27 | 30 | $sql .= "', tun_height='" . $_GET['tun_height'] / 100.0; |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
31 | $sql .= "', top_up_water='" . $_GET['top_up_water']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
32 | $sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
33 | $sql .= "', evap_rate='" . $_GET['evap_rate']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
34 | $sql .= "', boil_time='" . $_GET['boil_time']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
35 | ($_GET['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0"; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
36 | $sql .= "', top_up_kettle='" . $_GET['top_up_kettle']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
37 | $sql .= "', hop_utilization='" . $_GET['hop_utilization']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
38 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
39 | $sql .= "', lauter_volume='" . $_GET['lauter_volume']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
40 | $sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
41 | $sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace']; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
42 | $sql .= "', kettle_volume='" . $_GET['kettle_volume']; |
27 | 43 | $sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0; |
44 | $sql .= "', mash_volume='" . $_GET['mash_volume']; | |
45 | $sql .= "', efficiency='" . $_GET['efficiency']; | |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
46 | if (isset($_GET['insert'])) { |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
47 | $sql .= "';"; |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
48 | } |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
49 | if (isset($_GET['update'])) { |
116
ac993ef43b13
Removed all calculations from the equipemnts database script and added missing fields. Added missing fields to the inventory equipemnts edit screen. Added conditional batch size calculation to the equipments editor. Added specific heat settings to the equipments editor.
Michiel Broek <mbroek@mbse.eu>
parents:
115
diff
changeset
|
50 | $sql .= "' WHERE record='" . $_GET['record'] . "';"; |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
51 | } |
27 | 52 | $result = mysqli_query($connect, $sql); |
53 | if (! $result) { | |
54 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
55 | } else { | |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
56 | if (isset($_GET['update'])) { |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
57 | syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_GET['record']); |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
58 | } else { |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
59 | $lastid = mysqli_insert_id($connect); |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
60 | syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid); |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
61 | } |
27 | 62 | } |
63 | echo $result; | |
64 | ||
65 | } else if (isset($_GET['delete'])) { | |
66 | // DELETE COMMAND | |
67 | // FIXME: need to check if the record is in use | |
68 | $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_GET['record']."';"; | |
69 | $result = mysqli_query($connect, $sql); | |
70 | if (! $result) { | |
71 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
72 | } else { | |
73 | syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_GET['record']); | |
74 | } | |
75 | echo $result; | |
76 | ||
77 | } else { | |
78 | // SELECT COMMAND | |
79 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); | |
80 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
81 | $equipments[] = array( | |
82 | 'record' => $row['record'], | |
83 | 'name' => $row['name'], | |
84 | 'boil_size' => $row['boil_size'], | |
85 | 'batch_size' => $row['batch_size'], | |
86 | 'tun_volume' => $row['tun_volume'], | |
87 | 'tun_weight' => $row['tun_weight'], | |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
88 | 'tun_specific_heat' => $row['tun_specific_heat'], |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
89 | 'tun_material' => $row['tun_material'], |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
90 | 'tun_height' => $row['tun_height'] * 100.0, |
27 | 91 | 'top_up_water' => $row['top_up_water'], |
92 | 'trub_chiller_loss' => $row['trub_chiller_loss'], | |
93 | 'evap_rate' => $row['evap_rate'], | |
94 | 'boil_time' => $row['boil_time'], | |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
95 | 'calc_boil_volume' => $row['calc_boil_volume'], |
27 | 96 | 'top_up_kettle' => $row['top_up_kettle'], |
97 | 'hop_utilization' => $row['hop_utilization'], | |
98 | 'notes' => $row['notes'], | |
99 | 'lauter_volume' => $row['lauter_volume'], | |
115
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
100 | 'lauter_height' => $row['lauter_height'] * 100.0, |
ad31f4bd4036
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
Michiel Broek <mbroek@mbse.eu>
parents:
77
diff
changeset
|
101 | 'lauter_deadspace' => $row['lauter_deadspace'], |
27 | 102 | 'kettle_volume' => $row['kettle_volume'], |
103 | 'kettle_height' => $row['kettle_height'] * 100.0, | |
104 | 'mash_volume' => $row['mash_volume'], | |
105 | 'efficiency' => $row['efficiency'] | |
106 | ); | |
107 | } | |
108 | echo json_encode($equipments); | |
109 | } | |
110 | ?> |