Thu, 29 Nov 2018 23:21:42 +0100
Inventory database script added missing fields. Product database script added JOIN with the prod_recipes table.
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']; |
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
|
25 | $batch = '$_GET[\'boil_size\'] - ($_GET[\'evap_rate\'] * ($_GET[\'boil_time\'] / 60))'; |
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
|
26 | $sql .= "', batch_size='" . eval('return ' . $batch . ';'); |
27 | 27 | $sql .= "', tun_volume='" . $_GET['tun_volume']; |
28 | $sql .= "', tun_weight='" . $_GET['tun_weight']; | |
29 | $material = mysqli_real_escape_string($connect, $_GET['tun_material']); | |
30 | if ($material == "RVS") { | |
31 | $sql .= "', tun_specific_heat='0.11"; | |
32 | } else if ($material == "Aluminium") { | |
33 | $sql .= "', tun_specific_heat='0.22"; | |
34 | } else if ($material == "Kunststof") { | |
35 | $sql .= "', tun_specific_heat='0.46"; | |
36 | } else if ($material == "Koper") { | |
37 | $sql .= "', tun_specific_heat='0.092"; | |
38 | } | |
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
|
39 | $sql .= "', tun_material='" . $material; |
27 | 40 | $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
|
41 | $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
|
42 | $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
|
43 | $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
|
44 | $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
|
45 | ($_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
|
46 | $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
|
47 | $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
|
48 | $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
|
49 | $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
|
50 | $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
|
51 | $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
|
52 | $sql .= "', kettle_volume='" . $_GET['kettle_volume']; |
27 | 53 | $sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0; |
54 | $sql .= "', mash_volume='" . $_GET['mash_volume']; | |
55 | $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
|
56 | 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
|
57 | $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
|
58 | } |
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 | 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
|
60 | $sql .= "' WHERE 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
|
61 | } |
27 | 62 | $result = mysqli_query($connect, $sql); |
63 | if (! $result) { | |
64 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
65 | } 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
|
66 | 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
|
67 | 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
|
68 | } 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
|
69 | $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
|
70 | 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
|
71 | } |
27 | 72 | } |
73 | echo $result; | |
74 | ||
75 | } else if (isset($_GET['delete'])) { | |
76 | // DELETE COMMAND | |
77 | // FIXME: need to check if the record is in use | |
78 | $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_GET['record']."';"; | |
79 | $result = mysqli_query($connect, $sql); | |
80 | if (! $result) { | |
81 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
82 | } else { | |
83 | syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_GET['record']); | |
84 | } | |
85 | echo $result; | |
86 | ||
87 | } else { | |
88 | // SELECT COMMAND | |
89 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); | |
90 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
91 | $equipments[] = array( | |
92 | 'record' => $row['record'], | |
93 | 'name' => $row['name'], | |
94 | 'boil_size' => $row['boil_size'], | |
95 | 'batch_size' => $row['batch_size'], | |
96 | 'tun_volume' => $row['tun_volume'], | |
97 | '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
|
98 | '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
|
99 | '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
|
100 | 'tun_height' => $row['tun_height'] * 100.0, |
27 | 101 | 'top_up_water' => $row['top_up_water'], |
102 | 'trub_chiller_loss' => $row['trub_chiller_loss'], | |
103 | 'evap_rate' => $row['evap_rate'], | |
104 | '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
|
105 | 'calc_boil_volume' => $row['calc_boil_volume'], |
27 | 106 | 'top_up_kettle' => $row['top_up_kettle'], |
107 | 'hop_utilization' => $row['hop_utilization'], | |
108 | 'notes' => $row['notes'], | |
109 | '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
|
110 | '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
|
111 | 'lauter_deadspace' => $row['lauter_deadspace'], |
27 | 112 | 'kettle_volume' => $row['kettle_volume'], |
113 | 'kettle_height' => $row['kettle_height'] * 100.0, | |
114 | 'mash_volume' => $row['mash_volume'], | |
115 | 'efficiency' => $row['efficiency'] | |
116 | ); | |
117 | } | |
118 | echo json_encode($equipments); | |
119 | } | |
120 | ?> |