www/includes/db_inventory_equipments.php

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

mercurial