www/includes/db_inventory_equipments.php

changeset 115
ad31f4bd4036
parent 77
a9f8de2d7b2b
child 116
ac993ef43b13
--- a/www/includes/db_inventory_equipments.php	Wed Nov 28 21:57:06 2018 +0100
+++ b/www/includes/db_inventory_equipments.php	Thu Nov 29 23:21:42 2018 +0100
@@ -11,26 +11,22 @@
 
 // get data and store in a json array
 $query = "SELECT * FROM inventory_equipments ORDER BY name";
-if (isset($_GET['insert'])) {
-	// INSERT COMMAND
-	$sql  = "INSERT INTO `inventory_equipments` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
+if (isset($_GET['insert']) || isset($_GET['update'])) {
+	if (isset($_GET['insert'])) {
+		// INSERT COMMAND
+		$sql  = "INSERT INTO `inventory_equipments` SET ";
+	}
+	if (isset($_GET['update'])) {
+		// UPDATE COMMAND
+		$sql  = "UPDATE `inventory_equipments` SET ";
+	}
+	$sql .=    "name='" . mysqli_real_escape_string($connect, $_GET['name']);
 	$sql .= "', boil_size='" . $_GET['boil_size'];
+	$batch = '$_GET[\'boil_size\'] - ($_GET[\'evap_rate\'] * ($_GET[\'boil_time\'] / 60))';
+	$sql .= "', batch_size='" . eval('return ' . $batch . ';');
 	$sql .= "', tun_volume='" . $_GET['tun_volume'];
 	$sql .= "', tun_weight='" . $_GET['tun_weight'];
-	$sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss'];
-	$sql .= "', evap_rate='" . $_GET['evap_rate'];
-	$sql .= "', boil_time='" . $_GET['boil_time'];
-	$sql .= "', calc_boil_volume='Y";
-	$batch = '$_GET[\'boil_size\'] - ($_GET[\'evap_rate\'] * ($_GET[\'boil_time\'] / 60))';
-	$sql .= "', batch_size='" . eval('return ' . $batch . ';');
-	$sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace'];
-	$sql .= "', top_up_kettle='" . $_GET['top_up_kettle'];
-	$sql .= "', hop_utilization='" . $_GET['hop_utilization'];
-	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
-	$sql .= "', lauter_volume='" . $_GET['lauter_volume'];
-	$sql .= "', kettle_volume='" . $_GET['kettle_volume'];
 	$material = mysqli_real_escape_string($connect, $_GET['tun_material']);
-	$sql .= "', tun_material='" . $material;
 	if ($material == "RVS") {
 		$sql .= "', tun_specific_heat='0.11";
 	} else if ($material == "Aluminium") {
@@ -40,60 +36,39 @@
 	} else if ($material == "Koper") {
 		$sql .= "', tun_specific_heat='0.092";
 	}
+	$sql .= "', tun_material='" . $material;
 	$sql .= "', tun_height='" . $_GET['tun_height'] / 100.0;
+	$sql .= "', top_up_water='" . $_GET['top_up_water'];
+	$sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss'];
+	$sql .= "', evap_rate='" . $_GET['evap_rate'];
+	$sql .= "', boil_time='" . $_GET['boil_time'];
+	($_GET['calc_boil_volume'] == 'true') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0";
+	$sql .= "', top_up_kettle='" . $_GET['top_up_kettle'];
+	$sql .= "', hop_utilization='" . $_GET['hop_utilization'];
+	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
+	$sql .= "', lauter_volume='" . $_GET['lauter_volume'];
+	$sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0;
+	$sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace'];
+	$sql .= "', kettle_volume='" . $_GET['kettle_volume'];
 	$sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0;
-	$sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0;
 	$sql .= "', mash_volume='" . $_GET['mash_volume'];
 	$sql .= "', efficiency='" . $_GET['efficiency'];
-	$sql .= "';";
+	if (isset($_GET['insert'])) {
+		$sql .= "';";
+	}
+	if (isset($_GET['update'])) {
+	$sql .= "' WHERE record='" . $_GET['record'] . "';";
+	}
 	$result = mysqli_query($connect, $sql);
 	if (! $result) {
 		syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
 	} else {
-		syslog(LOG_NOTICE, "db_inventory_equipment: inserted ".$_GET['name']);
-	}
-	echo $result;
-
-} else if (isset($_GET['update'])) {
-	// UPDATE COMMAND
-	$sql  = "UPDATE `inventory_equipments` SET name='" . mysqli_real_escape_string($connect, $_GET['name']);
-	$sql .= "', boil_size='" . $_GET['boil_size'];
-	$sql .= "', tun_volume='" . $_GET['tun_volume'];
-	$sql .= "', tun_weight='" . $_GET['tun_weight'];
-	$sql .= "', trub_chiller_loss='" . $_GET['trub_chiller_loss'];
-	$sql .= "', evap_rate='" . $_GET['evap_rate'];
-	$sql .= "', boil_time='" . $_GET['boil_time'];
-	$sql .= "', calc_boil_volume='Y";
-	$batch = '$_GET[\'boil_size\'] - ($_GET[\'evap_rate\'] * ($_GET[\'boil_time\'] / 60))';
-	$sql .= "', batch_size='" . eval('return ' . $batch . ';'); 
-	$sql .= "', lauter_deadspace='" . $_GET['lauter_deadspace'];
-	$sql .= "', top_up_kettle='" . $_GET['top_up_kettle'];
-	$sql .= "', hop_utilization='" . $_GET['hop_utilization'];
-	$sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']);
-	$sql .= "', lauter_volume='" . $_GET['lauter_volume'];
-	$sql .= "', kettle_volume='" . $_GET['kettle_volume'];
-	$material = mysqli_real_escape_string($connect, $_GET['tun_material']);
-	$sql .= "', tun_material='" . $material;
-	if ($material == "RVS") {
-                $sql .= "', tun_specific_heat='0.11";
-	} else if ($material == "Aluminium") {
-		$sql .= "', tun_specific_heat='0.22";
-	} else if ($material == "Kunststof") {
-		$sql .= "', tun_specific_heat='0.46";
-	} else if ($material == "Koper") {
-		$sql .= "', tun_specific_heat='0.092";
-	}
-	$sql .= "', tun_height='" . $_GET['tun_height'] / 100.0;
-	$sql .= "', kettle_height='" . $_GET['kettle_height'] / 100.0;
-	$sql .= "', lauter_height='" . $_GET['lauter_height'] / 100.0;
-	$sql .= "', mash_volume='" . $_GET['mash_volume'];
-	$sql .= "', efficiency='" . $_GET['efficiency'];
-	$sql .= "' WHERE record='" . $_GET['record'] . "';";
-	$result = mysqli_query($connect, $sql);
-	if (! $result) {
-		syslog(LOG_NOTICE, "db_inventory_equipment: ".$sql." result: ".mysqli_error($connect));
-	} else {
-		syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_GET['record']);
+		if (isset($_GET['update'])) {
+			syslog(LOG_NOTICE, "db_inventory_equipment: updated record ".$_GET['record']);
+		} else {
+			$lastid = mysqli_insert_id($connect);
+			syslog(LOG_NOTICE, "db_inventory_equipment: inserted record ".$lastid);
+		}
 	}
 	echo $result;
 
@@ -120,20 +95,22 @@
 			'batch_size' => $row['batch_size'],
 			'tun_volume' => $row['tun_volume'],
 			'tun_weight' => $row['tun_weight'],
+			'tun_specific_heat' => $row['tun_specific_heat'],
+			'tun_material' => $row['tun_material'],
+			'tun_height' => $row['tun_height'] * 100.0,
 			'top_up_water' => $row['top_up_water'],
 			'trub_chiller_loss' => $row['trub_chiller_loss'],
 			'evap_rate' => $row['evap_rate'],
 			'boil_time' => $row['boil_time'],
-			'lauter_deadspace' => $row['lauter_deadspace'],
+			'calc_boil_volume' => $row['calc_boil_volume'],
 			'top_up_kettle' => $row['top_up_kettle'],
 			'hop_utilization' => $row['hop_utilization'],
 			'notes' => $row['notes'],
 			'lauter_volume' => $row['lauter_volume'],
+			'lauter_height' => $row['lauter_height'] * 100.0,
+			'lauter_deadspace' => $row['lauter_deadspace'],
 			'kettle_volume' => $row['kettle_volume'],
-			'tun_material' => $row['tun_material'],
-			'tun_height' => $row['tun_height'] * 100.0,
 			'kettle_height' => $row['kettle_height'] * 100.0,
-			'lauter_height' => $row['lauter_height'] * 100.0,
 			'mash_volume' => $row['mash_volume'],
 			'efficiency' => $row['efficiency']
 		);

mercurial