Tue, 28 Aug 2018 20:54:53 +0200
Finished mash steps editing. Style sheets cleanup.
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 | } | |
10 | ||
11 | // 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
|
12 | $query = "SELECT * FROM inventory_equipments ORDER BY name"; |
27 | 13 | if (isset($_GET['insert'])) { |
14 | // INSERT COMMAND | |
15 | $sql = "INSERT INTO `inventory_equipments` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
16 | $sql .= "', boil_size='" . $_GET['boil_size']; | |
17 | $sql .= "', tun_volume='" . $_GET['tun_volume']; | |
18 | $sql .= "', tun_weight='" . $_GET['tun_weight']; | |
19 | $sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss']; | |
20 | $sql .= "', evap_rate='" . $_GET['evap_rate']; | |
21 | $sql .= "', boil_time='" . $_GET['boil_time']; | |
22 | $sql .= "', calc_boil_volume='Y"; | |
23 | $batch = '$_GET[\'boil_size\'] - ($_GET[\'evap_rate\'] * ($_GET[\'boil_time\'] / 60))'; | |
24 | $sql .= "', batch_size='" . eval('return ' . $batch . ';'); | |
25 | $sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace']; | |
26 | $sql .= "', top_up_kettle='" . $_GET['top_up_kettle']; | |
27 | $sql .= "', hop_utilization='" . $_GET['hop_utilization']; | |
28 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
29 | $sql .= "', lauter_volume='" . $_GET['lauter_volume']; | |
30 | $sql .= "', kettle_volume='" . $_GET['kettle_volume']; | |
31 | $material = mysqli_real_escape_string($connect, $_GET['tun_material']); | |
32 | $sql .= "', tun_material='" . $material; | |
33 | if ($material == "RVS") { | |
34 | $sql .= "', tun_specific_heat='0.11"; | |
35 | } else if ($material == "Aluminium") { | |
36 | $sql .= "', tun_specific_heat='0.22"; | |
37 | } else if ($material == "Kunststof") { | |
38 | $sql .= "', tun_specific_heat='0.46"; | |
39 | } else if ($material == "Koper") { | |
40 | $sql .= "', tun_specific_heat='0.092"; | |
41 | } | |
42 | $sql .= "', tun_height='" . $_GET['tun_height'] / 100.0; | |
43 | $sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0; | |
44 | $sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0; | |
45 | $sql .= "', mash_volume='" . $_GET['mash_volume']; | |
46 | $sql .= "', efficiency='" . $_GET['efficiency']; | |
47 | $sql .= "';"; | |
48 | $result = mysqli_query($connect, $sql); | |
49 | if (! $result) { | |
50 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
51 | } else { | |
52 | syslog(LOG_NOTICE, "db_inventory_equipment: inserted ".$_GET['name']); | |
53 | } | |
54 | echo $result; | |
55 | ||
56 | } else if (isset($_GET['update'])) { | |
57 | // UPDATE COMMAND | |
58 | $sql = "UPDATE `inventory_equipments` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
59 | $sql .= "', boil_size='" . $_GET['boil_size']; | |
60 | $sql .= "', tun_volume='" . $_GET['tun_volume']; | |
61 | $sql .= "', tun_weight='" . $_GET['tun_weight']; | |
62 | $sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss']; | |
63 | $sql .= "', evap_rate='" . $_GET['evap_rate']; | |
64 | $sql .= "', boil_time='" . $_GET['boil_time']; | |
65 | $sql .= "', calc_boil_volume='Y"; | |
66 | $batch = '$_GET[\'boil_size\'] - ($_GET[\'evap_rate\'] * ($_GET[\'boil_time\'] / 60))'; | |
67 | $sql .= "', batch_size='" . eval('return ' . $batch . ';'); | |
68 | $sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace']; | |
69 | $sql .= "', top_up_kettle='" . $_GET['top_up_kettle']; | |
70 | $sql .= "', hop_utilization='" . $_GET['hop_utilization']; | |
71 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
72 | $sql .= "', lauter_volume='" . $_GET['lauter_volume']; | |
73 | $sql .= "', kettle_volume='" . $_GET['kettle_volume']; | |
74 | $material = mysqli_real_escape_string($connect, $_GET['tun_material']); | |
75 | $sql .= "', tun_material='" . $material; | |
76 | if ($material == "RVS") { | |
77 | $sql .= "', tun_specific_heat='0.11"; | |
78 | } else if ($material == "Aluminium") { | |
79 | $sql .= "', tun_specific_heat='0.22"; | |
80 | } else if ($material == "Kunststof") { | |
81 | $sql .= "', tun_specific_heat='0.46"; | |
82 | } else if ($material == "Koper") { | |
83 | $sql .= "', tun_specific_heat='0.092"; | |
84 | } | |
85 | $sql .= "', tun_height='" . $_GET['tun_height'] / 100.0; | |
86 | $sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0; | |
87 | $sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0; | |
88 | $sql .= "', mash_volume='" . $_GET['mash_volume']; | |
89 | $sql .= "', efficiency='" . $_GET['efficiency']; | |
90 | $sql .= "' WHERE record='" . $_GET['record'] . "';"; | |
91 | $result = mysqli_query($connect, $sql); | |
92 | if (! $result) { | |
93 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
94 | } else { | |
95 | syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_GET['record']); | |
96 | } | |
97 | echo $result; | |
98 | ||
99 | } else if (isset($_GET['delete'])) { | |
100 | // DELETE COMMAND | |
101 | // FIXME: need to check if the record is in use | |
102 | $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_GET['record']."';"; | |
103 | $result = mysqli_query($connect, $sql); | |
104 | if (! $result) { | |
105 | syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); | |
106 | } else { | |
107 | syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_GET['record']); | |
108 | } | |
109 | echo $result; | |
110 | ||
111 | } else { | |
112 | // SELECT COMMAND | |
113 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); | |
114 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
115 | $equipments[] = array( | |
116 | 'record' => $row['record'], | |
117 | 'name' => $row['name'], | |
118 | 'boil_size' => $row['boil_size'], | |
119 | 'batch_size' => $row['batch_size'], | |
120 | 'tun_volume' => $row['tun_volume'], | |
121 | 'tun_weight' => $row['tun_weight'], | |
122 | 'top_up_water' => $row['top_up_water'], | |
123 | 'trub_chiller_loss' => $row['trub_chiller_loss'], | |
124 | 'evap_rate' => $row['evap_rate'], | |
125 | 'boil_time' => $row['boil_time'], | |
126 | 'lauter_deadspace' => $row['lauter_deadspace'], | |
127 | 'top_up_kettle' => $row['top_up_kettle'], | |
128 | 'hop_utilization' => $row['hop_utilization'], | |
129 | 'notes' => $row['notes'], | |
130 | 'lauter_volume' => $row['lauter_volume'], | |
131 | 'kettle_volume' => $row['kettle_volume'], | |
132 | 'tun_material' => $row['tun_material'], | |
133 | 'tun_height' => $row['tun_height'] * 100.0, | |
134 | 'kettle_height' => $row['kettle_height'] * 100.0, | |
135 | 'lauter_height' => $row['lauter_height'] * 100.0, | |
136 | 'mash_volume' => $row['mash_volume'], | |
137 | 'efficiency' => $row['efficiency'] | |
138 | ); | |
139 | } | |
140 | echo json_encode($equipments); | |
141 | } | |
142 | ?> |