www/includes/db_inventory_equipments.php

changeset 209
dc30801e6961
parent 149
ff45488d480e
child 296
69fadd1aded2
equal deleted inserted replaced
208:578c78abf058 209:dc30801e6961
7 if (! $connect) { 7 if (! $connect) {
8 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); 8 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
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 if (isset($_POST['insert']) || isset($_POST['update'])) {
13 $query = "SELECT * FROM inventory_equipments ORDER BY name"; 13 if (isset($_POST['insert'])) {
14 if (isset($_GET['insert']) || isset($_GET['update'])) {
15 if (isset($_GET['insert'])) {
16 // INSERT COMMAND 14 // INSERT COMMAND
17 $sql = "INSERT INTO `inventory_equipments` SET "; 15 $sql = "INSERT INTO `inventory_equipments` SET ";
18 } 16 }
19 if (isset($_GET['update'])) { 17 if (isset($_POST['update'])) {
20 // UPDATE COMMAND 18 // UPDATE COMMAND
21 $sql = "UPDATE `inventory_equipments` SET "; 19 $sql = "UPDATE `inventory_equipments` SET ";
22 } 20 }
23 $sql .= "name='" . mysqli_real_escape_string($connect, $_GET['name']); 21 $sql .= "name='" . mysqli_real_escape_string($connect, $_POST['name']);
24 $sql .= "', boil_size='" . $_GET['boil_size']; 22 $sql .= "', boil_size='" . $_POST['boil_size'];
25 $sql .= "', batch_size='" . $_GET['batch_size']; 23 $sql .= "', batch_size='" . $_POST['batch_size'];
26 $sql .= "', tun_volume='" . $_GET['tun_volume']; 24 $sql .= "', tun_volume='" . $_POST['tun_volume'];
27 $sql .= "', tun_weight='" . $_GET['tun_weight']; 25 $sql .= "', tun_weight='" . $_POST['tun_weight'];
28 $sql .= "', tun_specific_heat='" . $_GET['tun_specific_heat']; 26 $sql .= "', tun_specific_heat='" . $_POST['tun_specific_heat'];
29 $sql .= "', tun_material='" . mysqli_real_escape_string($connect, $_GET['tun_material']); 27 $sql .= "', tun_material='" . $_POST['tun_material'];
30 $sql .= "', tun_height='" . $_GET['tun_height'] / 100.0; 28 $sql .= "', tun_height='" . floatval($_POST['tun_height']) / 100.0;
31 $sql .= "', top_up_water='" . $_GET['top_up_water']; 29 $sql .= "', top_up_water='" . $_POST['top_up_water'];
32 $sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss']; 30 $sql .= "', trub_chiller_loss='" . $_POST['trub_chiller_loss'];
33 $sql .= "', evap_rate='" . $_GET['evap_rate']; 31 $sql .= "', evap_rate='" . $_POST['evap_rate'];
34 $sql .= "', boil_time='" . $_GET['boil_time']; 32 $sql .= "', boil_time='" . $_POST['boil_time'];
35 ($_GET['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0"; 33 ($_POST['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0";
36 $sql .= "', top_up_kettle='" . $_GET['top_up_kettle']; 34 $sql .= "', top_up_kettle='" . $_POST['top_up_kettle'];
37 $sql .= "', hop_utilization='" . $_GET['hop_utilization']; 35 $sql .= "', hop_utilization='" . $_POST['hop_utilization'];
38 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); 36 $sql .= "', notes='" . mysqli_real_escape_string($connect, $_POST['notes']);
39 $sql .= "', lauter_volume='" . $_GET['lauter_volume']; 37 $sql .= "', lauter_volume='" . $_POST['lauter_volume'];
40 $sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0; 38 $sql .= "', lauter_height='" . floatval($_POST['lauter_height']) / 100.0;
41 $sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace']; 39 $sql .= "', lauter_deadspace='" . $_POST['lauter_deadspace'];
42 $sql .= "', kettle_volume='" . $_GET['kettle_volume']; 40 $sql .= "', kettle_volume='" . $_POST['kettle_volume'];
43 $sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0; 41 $sql .= "', kettle_height='" . floatval($_POST['kettle_height']) / 100.0;
44 $sql .= "', mash_volume='" . $_GET['mash_volume']; 42 $sql .= "', mash_volume='" . $_POST['mash_volume'];
45 $sql .= "', mash_max='" . $_GET['mash_max']; 43 $sql .= "', mash_max='" . $_POST['mash_max'];
46 $sql .= "', efficiency='" . $_GET['efficiency']; 44 $sql .= "', efficiency='" . $_POST['efficiency'];
47 if (isset($_GET['insert'])) { 45 if (isset($_POST['insert'])) {
48 $sql .= "';"; 46 $sql .= "';";
49 } 47 }
50 if (isset($_GET['update'])) { 48 if (isset($_POST['update'])) {
51 $sql .= "' WHERE record='" . $_GET['record'] . "';"; 49 $sql .= "' WHERE record='" . $_POST['record'] . "';";
52 } 50 }
53 $result = mysqli_query($connect, $sql); 51 $result = mysqli_query($connect, $sql);
54 if (! $result) { 52 if (! $result) {
55 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); 53 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
56 } else { 54 } else {
57 if (isset($_GET['update'])) { 55 if (isset($_POST['update'])) {
58 syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_GET['record']); 56 syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_POST['record']);
59 } else { 57 } else {
60 $lastid = mysqli_insert_id($connect); 58 $lastid = mysqli_insert_id($connect);
61 syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid); 59 syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid);
62 } 60 }
63 } 61 }
64 echo $result; 62 echo $result;
65 63
66 } else if (isset($_GET['delete'])) { 64 } else if (isset($_POST['delete'])) {
67 // DELETE COMMAND 65 // DELETE COMMAND
68 // FIXME: need to check if the record is in use 66 // FIXME: need to check if the record is in use
69 $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_GET['record']."';"; 67 $sql = "DELETE FROM `inventory_equipments` WHERE record='".$_POST['record']."';";
70 $result = mysqli_query($connect, $sql); 68 $result = mysqli_query($connect, $sql);
71 if (! $result) { 69 if (! $result) {
72 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect)); 70 syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
73 } else { 71 } else {
74 syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_GET['record']); 72 syslog(LOG_NOTICE, "db_inventory_equipment: deleted record ".$_POST['record']);
75 } 73 }
76 echo $result; 74 echo $result;
77 75
78 } else { 76 } else {
79 // SELECT COMMAND 77 // SELECT COMMAND
78 $query = "SELECT * FROM inventory_equipments ORDER BY name";
80 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 79 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
81 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 80 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
82 $equipments[] = array( 81 $equipments[] = array(
83 'record' => $row['record'], 82 'record' => $row['record'],
84 'name' => $row['name'], 83 'name' => $row['name'],
86 'batch_size' => $row['batch_size'], 85 'batch_size' => $row['batch_size'],
87 'tun_volume' => $row['tun_volume'], 86 'tun_volume' => $row['tun_volume'],
88 'tun_weight' => $row['tun_weight'], 87 'tun_weight' => $row['tun_weight'],
89 'tun_specific_heat' => $row['tun_specific_heat'], 88 'tun_specific_heat' => $row['tun_specific_heat'],
90 'tun_material' => $row['tun_material'], 89 'tun_material' => $row['tun_material'],
91 'tun_height' => $row['tun_height'] * 100.0, 90 'tun_height' => floatval($row['tun_height']) * 100.0,
92 'top_up_water' => $row['top_up_water'], 91 'top_up_water' => $row['top_up_water'],
93 'trub_chiller_loss' => $row['trub_chiller_loss'], 92 'trub_chiller_loss' => $row['trub_chiller_loss'],
94 'evap_rate' => $row['evap_rate'], 93 'evap_rate' => $row['evap_rate'],
95 'boil_time' => $row['boil_time'], 94 'boil_time' => $row['boil_time'],
96 'calc_boil_volume' => $row['calc_boil_volume'], 95 'calc_boil_volume' => $row['calc_boil_volume'],
97 'top_up_kettle' => $row['top_up_kettle'], 96 'top_up_kettle' => $row['top_up_kettle'],
98 'hop_utilization' => $row['hop_utilization'], 97 'hop_utilization' => $row['hop_utilization'],
99 'notes' => $row['notes'], 98 'notes' => $row['notes'],
100 'lauter_volume' => $row['lauter_volume'], 99 'lauter_volume' => $row['lauter_volume'],
101 'lauter_height' => $row['lauter_height'] * 100.0, 100 'lauter_height' => floatval($row['lauter_height']) * 100.0,
102 'lauter_deadspace' => $row['lauter_deadspace'], 101 'lauter_deadspace' => $row['lauter_deadspace'],
103 'kettle_volume' => $row['kettle_volume'], 102 'kettle_volume' => $row['kettle_volume'],
104 'kettle_height' => $row['kettle_height'] * 100.0, 103 'kettle_height' => floatval($row['kettle_height']) * 100.0,
105 'mash_volume' => $row['mash_volume'], 104 'mash_volume' => $row['mash_volume'],
106 'mash_max' => $row['mash_max'], 105 'mash_max' => $row['mash_max'],
107 'efficiency' => $row['efficiency'] 106 'efficiency' => $row['efficiency']
108 ); 107 );
109 } 108 }

mercurial