www/import/from_brouwhulp.php

changeset 151
2c9cfe2f0860
parent 150
159d7a89fcef
child 152
2e4249add363
--- a/www/import/from_brouwhulp.php	Mon Dec 24 15:52:11 2018 +0100
+++ b/www/import/from_brouwhulp.php	Mon Dec 24 23:10:52 2018 +0100
@@ -974,14 +974,10 @@
         $len_mash = 0;
 
         echo "  Start adding brews to the database\n";
-        $psql = "TRUNCATE TABLE prod_main;";
-        if (! $presult = mysqli_query($db, $psql)) {
+        $sql = "TRUNCATE TABLE products;";
+        if (! $presult = mysqli_query($db, $sql)) {
                 printf("Error: %s\n", mysqli_error($db));
 	}
-	$rsql = "TRUNCATE TABLE prod_recipes;";
-	if (! $rresult = mysqli_query($db, $rsql)) {
-		printf("Error: %s\n", mysqli_error($db));
-	}
 
 	date_default_timezone_set('Europe/Amsterdam');
         $recipes = simplexml_load_file($brouwhulp . '/brews.xml');
@@ -999,75 +995,70 @@
 		$stage = "Plan";	// Default value.
                 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
 
-		$psql  = "INSERT INTO prod_main SET puuid='" . $uuid;		// So we can link the records.
-		$rsql  = "INSERT INTO prod_recipes SET uuid='" . $uuid;
-
-		$psql .= "', pname='" . mysqli_real_escape_string($db, $recipe->NAME);
-		$rsql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
+		$sql  = "INSERT INTO products SET uuid='" . $uuid;
+		$sql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
 
                 if ($recipe->NOTES) {
-			$rsql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES);		// Duplicate the notes
-			$psql .= "', pnotes='" . mysqli_real_escape_string($db, $recipe->NOTES);
+			$sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES);
 		} else {
-			$rsql .= "', notes='";
-			$psql .= "', pnotes='";
+			$sql .= "', notes='";
 		}
                 if ($recipe->TYPE)
-                        $rsql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE);
+                        $sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE);
                 else
-                        $rsql .= "', type='";
+                        $sql .= "', type='";
                 if ($recipe->BATCH_SIZE)
                         $batch_size = floatval($recipe->BATCH_SIZE);
-                $rsql .= "', batch_size='" . $batch_size;
+                $sql .= "', batch_size='" . $batch_size;
                 if ($recipe->BOIL_SIZE)
                         $boil_size = floatval($recipe->BOIL_SIZE);
-                $rsql .= "', boil_size='" . $boil_size;
+                $sql .= "', boil_size='" . $boil_size;
                 if ($recipe->BOIL_TIME)
-                        $rsql .= "', boil_time='" . floatval($recipe->BOIL_TIME);
+                        $sql .= "', boil_time='" . floatval($recipe->BOIL_TIME);
                 else
-                        $rsql .= "', boil_time='90";
+                        $sql .= "', boil_time='90";
                 if ($recipe->EFFICIENCY)
                         $efficiency = floatval($recipe->EFFICIENCY);
-                $rsql .= "', efficiency='" . $efficiency;
+                $sql .= "', efficiency='" . $efficiency;
                 /* Don't use $recipe->EST_OG but recalculate it */
                 /* Don't use $recipe->EST_FG but recalculate it */
                 /* Don't use $recipe->EST_COLOR but recalculate it */
                 if ($recipe->COLOR_METHOD)
-                        $rsql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD);
+                        $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD);
                 if ($recipe->IBU)
-                        $rsql .= "', est_ibu='" . floatval($recipe->IBU);
+                        $sql .= "', est_ibu='" . floatval($recipe->IBU);
                 if ($recipe->IBU_METHOD)
-                        $rsql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD);
+                        $sql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD);
                 if ($recipe->CARBONATION)
-                        $rsql .= "', est_carb='" . floatval($recipe->CARBONATION);
+                        $sql .= "', est_carb='" . floatval($recipe->CARBONATION);
 
                 if ($recipe->STYLE) {
-                        $rsql .= recipe_style($recipe);
+                        $sql .= recipe_style($recipe);
                 }
 
 		if ($recipe->CALC_ACID) {
-			($recipe->CALC_ACID == "TRUE") ? $rsql .= "', calc_acid='1" : $rsql .= "', calc_acid='0";
+			($recipe->CALC_ACID == "TRUE") ? $sql .= "', calc_acid='1" : $sql .= "', calc_acid='0";
 		}
 		if ($recipe->TARGET_PH) {
-			 $rsql .= "', mash_ph='" . floatval($recipe->TARGET_PH);
+			 $sql .= "', mash_ph='" . floatval($recipe->TARGET_PH);
 		}
 		if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Lactic")) {
-			$rsql .= "', sparge_acid_type='Melkzuur";
+			$sql .= "', sparge_acid_type='Melkzuur";
 		} else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Hydrochloric")) {
-			$rsql .= "', sparge_acid_type='Zoutzuur";
+			$sql .= "', sparge_acid_type='Zoutzuur";
 		} else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Phosphoric")) {
-			$rsql .= "', sparge_acid_type='Fosforzuur";
+			$sql .= "', sparge_acid_type='Fosforzuur";
 		} else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Sulfuric")) {
-			$rsql .= "', sparge_acid_type='Zwavelzuur";
+			$sql .= "', sparge_acid_type='Zwavelzuur";
 		}
 		if ($recipe->ACID_SPARGE_PERC) {
-			$rsql .= "', sparge_acid_perc='" . floatval($recipe->ACID_SPARGE_PERC);
+			$sql .= "', sparge_acid_perc='" . floatval($recipe->ACID_SPARGE_PERC);
 		}
 		if ($recipe->LACTIC_SPARGE) {
-			$rsql .= "', sparge_acid_amount='" . floatval($recipe->LACTIC_SPARGE);
+			$sql .= "', sparge_acid_amount='" . floatval($recipe->LACTIC_SPARGE);
 		}
 		if ($recipe->VOLUME_HLT) {
-			$rsql .= "', sparge_volume='" . floatval($recipe->VOLUME_HLT);
+			$sql .= "', sparge_volume='" . floatval($recipe->VOLUME_HLT);
 		}
 
                 /*
@@ -1075,7 +1066,7 @@
                  */
                 if ($recipe->FERMENTABLES) {
                         $fermentables = recipe_fermentables($recipe);
-                        $rsql .= "', json_fermentables='" . $fermentables;
+                        $sql .= "', json_fermentables='" . $fermentables;
                         if (strlen($fermentables) > $len_fermentables)
                                 $len_fermentables = strlen($fermentables);
                 }
@@ -1085,7 +1076,7 @@
                  */
                 if ($recipe->HOPS) {
                         $hops = recipe_hops($recipe);
-                        $rsql .= "', json_hops='" . $hops;
+                        $sql .= "', json_hops='" . $hops;
                         if (strlen($hops) > $len_hops)
                                 $len_hops = strlen($hops);
                 }
@@ -1095,7 +1086,7 @@
                  */
                 if ($recipe->MISCS) {
                         $miscs = recipe_miscs($recipe);
-                        $rsql .= "', json_miscs='" . $miscs;
+                        $sql .= "', json_miscs='" . $miscs;
                         if (strlen($miscs) > $len_miscs)
                                 $len_miscs = strlen($miscs);
                 }
@@ -1105,7 +1096,7 @@
                  */
                 if ($recipe->YEASTS) {
                         $yeasts = recipe_yeasts($recipe);
-                        $rsql .= "', json_yeasts='" . $yeasts;
+                        $sql .= "', json_yeasts='" . $yeasts;
                         if (strlen($yeasts) > $len_yeasts)
                                 $len_yeasts = strlen($yeasts);
                 }
@@ -1114,21 +1105,21 @@
                  * Get the waters
                  */
                 if ($recipe->WATERS) {
-                        $rsql .= recipe_waters($recipe, $db);
+                        $sql .= recipe_waters($recipe, $db);
                 }
 
                 /*
                  * Put the mash in a json array
                  */
                 if ($recipe->MASH) {
-                        $rsql .= "',sparge_temp='" . floatval($recipe->MASH->SPARGE_TEMP);
-                        $rsql .= "',sparge_ph='" . floatval($recipe->MASH->PH);
+                        $sql .= "',sparge_temp='" . floatval($recipe->MASH->SPARGE_TEMP);
+                        $sql .= "',sparge_ph='" . floatval($recipe->MASH->PH);
                         if ($recipe->MASH->NAME)
-                                $rsql .= "',mash_name='" . mysqli_real_escape_string($db, $recipe->MASH->NAME);
+                                $sql .= "',mash_name='" . mysqli_real_escape_string($db, $recipe->MASH->NAME);
 
                         if ($recipe->MASH->MASH_STEPS) {
                                 $steps = recipe_mash_steps($recipe);
-                                $rsql .= "', json_mashs='" . $steps;
+                                $sql .= "', json_mashs='" . $steps;
                                 if (strlen($steps) > $len_mash)
                                         $len_mash = strlen($steps);
                         }
@@ -1139,41 +1130,41 @@
                  *  OG, FG, color, IBU
                  */
                 $og = estimate_sg($f_sugars, $batch_size);
-                $rsql .= "', est_og='" . floatval($og);
+                $sql .= "', est_og='" . floatval($og);
                 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og);
-                $rsql .= "', est_fg='" . floatval($fg);
+                $sql .= "', est_fg='" . floatval($fg);
                 $abv = abvol($og, $fg);
-                $rsql .= "', est_abv='" . floatval($abv);
+                $sql .= "', est_abv='" . floatval($abv);
                 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw);
-                $rsql .= "', est_color='" . floatval($color);
-		$psql .= "', code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE);
+                $sql .= "', est_color='" . floatval($color);
+		$sql .= "', code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE);
 
 		/*
 		 * Update external logfiles
 		 */
-		$sql  = "UPDATE log_brews SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
-		$sql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
-		if (! $result = mysqli_query($db, $sql)) {
+		$lsql  = "UPDATE log_brews SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
+		$lsql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
+		if (! $result = mysqli_query($db, $lsql)) {
 			printf("Error: %s\n", mysqli_error($db));
 		}
 		$count = mysqli_affected_rows($db);
 		if ($count > 0) {
-			$psql .= "', log_brew='1";
+			$sql .= "', log_brew='1";
 		}
-		$sql  = "UPDATE log_fermentation SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
-		$sql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
-		if (! $result = mysqli_query($db, $sql)) {
+		$lsql  = "UPDATE log_fermentation SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
+		$lsql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
+		if (! $result = mysqli_query($db, $lsql)) {
 			printf("Error: %s\n", mysqli_error($db));
 		}
 		$count = mysqli_affected_rows($db);
 		if ($count > 0) {
-			$psql .= "', log_fermentation='1";
+			$sql .= "', log_fermentation='1";
 		} else {
 			// See if there really are no records
-			$sql  = "SELECT product_code FROM log_fermentation WHERE product_code='".$recipe->NR_RECIPE."';";
+			$lsql  = "SELECT product_code FROM log_fermentation WHERE product_code='".$recipe->NR_RECIPE."';";
 			$count = mysqli_affected_rows($db);
 			if ($count > 0) {
-				$psql .= "', log_fermentation='1";
+				$sql .= "', log_fermentation='1";
 			}
 		}
 
@@ -1199,47 +1190,47 @@
 					printf("Error: %s\n", mysqli_error($db));
 				}
 			}
-			$psql .= "', log_fermentation='1";
+			$sql .= "', log_fermentation='1";
 		}
 
 		if ($recipe->EQUIPMENT) {
-			$psql .= "', eq_name='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NAME);
-			$psql .= "', eq_notes='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NOTES);
-			$psql .= "', eq_boil_size='" . floatval($recipe->EQUIPMENT->BOIL_SIZE);
-			$psql .= "', eq_batch_size='" . floatval($recipe->EQUIPMENT->BATCH_SIZE);
-			$psql .= "', eq_tun_volume='" . floatval($recipe->EQUIPMENT->TUN_VOLUME);
-			$psql .= "', eq_tun_weight='" . floatval($recipe->EQUIPMENT->TUN_WEIGHT);
-			$psql .= "', eq_tun_specific_heat='" . floatval($recipe->EQUIPMENT->TUN_SPECIFIC_HEAT);
-			$psql .= "', eq_tun_material='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->TUN_MATERIAL);
-			$psql .= "', eq_tun_height='" . floatval($recipe->EQUIPMENT->TUN_HEIGHT);
+			$sql .= "', eq_name='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NAME);
+			$sql .= "', eq_notes='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NOTES);
+			$sql .= "', eq_boil_size='" . floatval($recipe->EQUIPMENT->BOIL_SIZE);
+			$sql .= "', eq_batch_size='" . floatval($recipe->EQUIPMENT->BATCH_SIZE);
+			$sql .= "', eq_tun_volume='" . floatval($recipe->EQUIPMENT->TUN_VOLUME);
+			$sql .= "', eq_tun_weight='" . floatval($recipe->EQUIPMENT->TUN_WEIGHT);
+			$sql .= "', eq_tun_specific_heat='" . floatval($recipe->EQUIPMENT->TUN_SPECIFIC_HEAT);
+			$sql .= "', eq_tun_material='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->TUN_MATERIAL);
+			$sql .= "', eq_tun_height='" . floatval($recipe->EQUIPMENT->TUN_HEIGHT);
 			if ($recipe->EQUIPMENT->TOP_UP_WATER)
-				$psql .= "', eq_top_up_water='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER);
-			$psql .= "', eq_trub_chiller_loss='" . floatval($recipe->EQUIPMENT->TRUB_CHILLER_LOSS);
+				$sql .= "', eq_top_up_water='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER);
+			$sql .= "', eq_trub_chiller_loss='" . floatval($recipe->EQUIPMENT->TRUB_CHILLER_LOSS);
 			/*
 			 * Brouwhulp uses a percentage for the evaporation rate. This is wrong
 			 * but was made so because the beerxml standard requires this. What we
 			 * do is calculate the actual evaporation and store that.
 			 * This is what we use. Brouwhulp calculates this on the fly.
 			 */
-			$psql .= "', eq_evap_rate='" . (floatval($recipe->EQUIPMENT->EVAP_RATE) * floatval($recipe->EQUIPMENT->BOIL_SIZE)) / 100;
-			$psql .= "', eq_boil_time='" . floatval($recipe->EQUIPMENT->BOIL_TIME);
-			($recipe->EQUIPMENT->CALC_BOIL_VOLUME == 'TRUE') ? $psql .= "', eq_calc_boil_volume='1" : $psql .= "', eq_calc_boil_volume='0";
+			$sql .= "', eq_evap_rate='" . (floatval($recipe->EQUIPMENT->EVAP_RATE) * floatval($recipe->EQUIPMENT->BOIL_SIZE)) / 100;
+			$sql .= "', eq_boil_time='" . floatval($recipe->EQUIPMENT->BOIL_TIME);
+			($recipe->EQUIPMENT->CALC_BOIL_VOLUME == 'TRUE') ? $sql .= "', eq_calc_boil_volume='1" : $sql .= "', eq_calc_boil_volume='0";
 			if ($recipe->EQUIPMENT->TOP_UP_KETTLE)
-				$psql .= "', eq_top_up_kettle='" . floatval($recipe->EQUIPMENT->TOP_UP_KETTLE);
-			$psql .= "', eq_hop_utilization='" . floatval($recipe->EQUIPMENT->HOP_UTILIZATION);
-			$psql .= "', eq_lauter_volume='" . floatval($recipe->EQUIPMENT->LAUTER_VOLUME);
-			$psql .= "', eq_lauter_height='" . floatval($recipe->EQUIPMENT->LAUTER_HEIGHT);
-			$psql .= "', eq_lauter_deadspace='" . floatval($recipe->EQUIPMENT->LAUTER_DEADSPACE);
-			$psql .= "', eq_kettle_volume='" . floatval($recipe->EQUIPMENT->KETTLE_VOLUME);
-			$psql .= "', eq_kettle_height='" . floatval($recipe->EQUIPMENT->KETTLE_HEIGHT);
-			$psql .= "', eq_mash_volume='" . floatval($recipe->EQUIPMENT->MASH_VOLUME);
-			$psql .= "', eq_mash_max='" . round((floatval($recipe->EQUIPMENT->MASH_VOLUME) / 3) * 10) / 10;     // Not in beerxml/brouwhulp. For RIMS systems.
-			$psql .= "', eq_efficiency='" . floatval($recipe->EQUIPMENT->EFFICIENCY);
+				$sql .= "', eq_top_up_kettle='" . floatval($recipe->EQUIPMENT->TOP_UP_KETTLE);
+			$sql .= "', eq_hop_utilization='" . floatval($recipe->EQUIPMENT->HOP_UTILIZATION);
+			$sql .= "', eq_lauter_volume='" . floatval($recipe->EQUIPMENT->LAUTER_VOLUME);
+			$sql .= "', eq_lauter_height='" . floatval($recipe->EQUIPMENT->LAUTER_HEIGHT);
+			$sql .= "', eq_lauter_deadspace='" . floatval($recipe->EQUIPMENT->LAUTER_DEADSPACE);
+			$sql .= "', eq_kettle_volume='" . floatval($recipe->EQUIPMENT->KETTLE_VOLUME);
+			$sql .= "', eq_kettle_height='" . floatval($recipe->EQUIPMENT->KETTLE_HEIGHT);
+			$sql .= "', eq_mash_volume='" . floatval($recipe->EQUIPMENT->MASH_VOLUME);
+			$sql .= "', eq_mash_max='" . round((floatval($recipe->EQUIPMENT->MASH_VOLUME) / 3) * 10) / 10;     // Not in beerxml/brouwhulp. For RIMS systems.
+			$sql .= "', eq_efficiency='" . floatval($recipe->EQUIPMENT->EFFICIENCY);
 		}
 
 		if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) {
 			/* We have a plan date but haven't brewed yet, use current date */
-			$psql .= "', birth='" . date("Y-m-d");
+			$sql .= "', birth='" . date("Y-m-d");
 			$stageno= 1;
 			$stage = "Wait";
 		}
@@ -1249,74 +1240,74 @@
 			$stageno = 3;
 			$stage = "Primary";	// Need to think about during a brew...
 			$brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2);
-			$psql .= "', birth='" . $brewdate;
+			$sql .= "', birth='" . $brewdate;
 			$date_start = $brewdate.' '.$recipe->TIME_STARTED;
 			$date_end   = $brewdate.' '.$recipe->TIME_ENDED;
-			$psql .= "', brew_date_start='" . $date_start;
+			$sql .= "', brew_date_start='" . $date_start;
 
 			if ($recipe->PH_ADJUSTED)
-				$psql .= "', brew_mash_ph='" . floatval($recipe->PH_ADJUSTED);
+				$sql .= "', brew_mash_ph='" . floatval($recipe->PH_ADJUSTED);
 			if (floatval($recipe->SG_END_MASH) != 1.0)
-				$psql .= "', brew_mash_sg='" . floatval($recipe->SG_END_MASH);
+				$sql .= "', brew_mash_sg='" . floatval($recipe->SG_END_MASH);
 			if ($recipe->MASH->SPARGE_TEMP)
-				$psql .= "', brew_sparge_temperature='" . floatval($recipe->MASH->SPARGE_TEMP);
+				$sql .= "', brew_sparge_temperature='" . floatval($recipe->MASH->SPARGE_TEMP);
 			if ($recipe->MASH->PH)
-				$psql .= "', brew_sparge_ph='" . floatval($recipe->MASH->PH);
+				$sql .= "', brew_sparge_ph='" . floatval($recipe->MASH->PH);
 			if ($recipe->VOLUME_HLT)
-				$psql .= "', brew_sparge_volume='" . floatval($recipe->VOLUME_HLT);
+				$sql .= "', brew_sparge_volume='" . floatval($recipe->VOLUME_HLT);
 			if ($recipe->VOLUME_BEFORE_BOIL)
-				$psql .= "', brew_preboil_volume='" . floatval($recipe->VOLUME_BEFORE_BOIL);
+				$sql .= "', brew_preboil_volume='" . floatval($recipe->VOLUME_BEFORE_BOIL);
 			if (floatval($recipe->OG_BEFORE_BOIL) != 1.0)
-				$psql .= "', brew_preboil_sg='" . floatval($recipe->OG_BEFORE_BOIL);
+				$sql .= "', brew_preboil_sg='" . floatval($recipe->OG_BEFORE_BOIL);
 			if ($recipe->PH_BEFORE_BOIL)
-				$psql .= "', brew_preboil_ph='" . floatval($recipe->PH_BEFORE_BOIL);
+				$sql .= "', brew_preboil_ph='" . floatval($recipe->PH_BEFORE_BOIL);
 			if ($recipe->VOLUME_AFTER_BOIL)
-				$psql .= "', brew_aboil_volume='" . floatval($recipe->VOLUME_AFTER_BOIL);
-			$psql .= "', brew_aboil_sg='" . floatval($recipe->OG);
+				$sql .= "', brew_aboil_volume='" . floatval($recipe->VOLUME_AFTER_BOIL);
+			$sql .= "', brew_aboil_sg='" . floatval($recipe->OG);
 			if ($recipe->PH_AFTER_BOIL)
-				$psql .= "', brew_aboil_ph='" . floatval($recipe->PH_AFTER_BOIL);
+				$sql .= "', brew_aboil_ph='" . floatval($recipe->PH_AFTER_BOIL);
 			if ($recipe->ACTUAL_EFFICIENCY)
-				$psql .= "', brew_aboil_efficiency='" . floatval($recipe->ACTUAL_EFFICIENCY);
-			$psql .= "', brew_whirlpool2='" . floatval($recipe->WHIRLPOOL_TIME);
-			$psql .= "', brew_cooling_method='" . mysqli_real_escape_string($db, $recipe->COOLING_METHOD);
-			$psql .= "', brew_cooling_time='" . floatval($recipe->COOLING_TIME);
-			$psql .= "', brew_cooling_to='" . floatval($recipe->COOLING_TO);
+				$sql .= "', brew_aboil_efficiency='" . floatval($recipe->ACTUAL_EFFICIENCY);
+			$sql .= "', brew_whirlpool2='" . floatval($recipe->WHIRLPOOL_TIME);
+			$sql .= "', brew_cooling_method='" . mysqli_real_escape_string($db, $recipe->COOLING_METHOD);
+			$sql .= "', brew_cooling_time='" . floatval($recipe->COOLING_TIME);
+			$sql .= "', brew_cooling_to='" . floatval($recipe->COOLING_TO);
 			if ($recipe->VOLUME_FERMENTER)
-				$psql .= "', brew_fermenter_volume='" . floatval($recipe->VOLUME_FERMENTER);
+				$sql .= "', brew_fermenter_volume='" . floatval($recipe->VOLUME_FERMENTER);
 			if ($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY)
-				$psql .= "', brew_fermenter_extrawater='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY);
-			$psql .= "', brew_fermenter_sg='" . floatval($recipe->OG_FERMENTER);
-			$psql .= "', brew_fermenter_ibu='" . floatval($recipe->IBU);
-			$psql .= "', brew_aeration_type='" . mysqli_real_escape_string($db, $recipe->AERATION_TYPE);
+				$sql .= "', brew_fermenter_extrawater='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY);
+			$sql .= "', brew_fermenter_sg='" . floatval($recipe->OG_FERMENTER);
+			$sql .= "', brew_fermenter_ibu='" . floatval($recipe->IBU);
+			$sql .= "', brew_aeration_type='" . mysqli_real_escape_string($db, $recipe->AERATION_TYPE);
 			if ($recipe->AERATION_TYPE != "None") {
-				$psql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED);
-				$psql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME);
+				$sql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED);
+				$sql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME);
 			}
-			$psql .= "', brew_date_end='" . $date_end;
+			$sql .= "', brew_date_end='" . $date_end;
 		}
 
 		if ($recipe->PRIMARY_AGE && ($stageno >= 3)) {
 			/* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */
 			$pdate = new DateTime($brewdate);
 			$pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days");
-			$psql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY);
-			$psql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY);
-			$psql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY);
-			$psql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY);
-			$psql .= "', primary_end_date='" . $pdate->format("Y-m-d");
+			$sql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY);
+			$sql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY);
+			$sql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY);
+			$sql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY);
+			$sql .= "', primary_end_date='" . $pdate->format("Y-m-d");
 			$stageno = 4;
 			$stage = "Secondary";
 
 			if ($recipe->SECONDARY_AGE && ($stageno >= 4)) {
 				$sdate = new DateTime($brewdate);
 				$sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days");
-				$psql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP);
-				$psql .= "', secondary_end_date='" . $sdate->format("Y-m-d");
+				$sql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP);
+				$sql .= "', secondary_end_date='" . $sdate->format("Y-m-d");
 				$stageno = 5;
 				$stage = "Tertiary";
 
 				if ($recipe->TERTIARY_TEMP && ($stageno >= 5)) {
-					$psql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP);
+					$sql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP);
 				}
 			}
 		}
@@ -1324,7 +1315,7 @@
 		if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) &&
 		    ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS) && ($stageno >= 5)) {
 			$bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2);
-			$psql .= "', package_date='" . $bdate;
+			$sql .= "', package_date='" . $bdate;
 			$stage = "Package";
 			$stageno = 6;
 			$dStart = new DateTime($bdate);
@@ -1346,61 +1337,54 @@
 			}
 
 			if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) {
-				$psql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING);
-				$psql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION);
-				$psql .= "', bottle_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_BOTTLES);
-				$psql .= "', bottle_priming_amount='" . floatval($recipe->AMOUNT_PRIMING);
-				$psql .= "', bottle_carbonation_temp='" . floatval($recipe->CARBONATION_TEMP);
+				$sql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING);
+				$sql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION);
+				$sql .= "', bottle_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_BOTTLES);
+				$sql .= "', bottle_priming_amount='" . floatval($recipe->AMOUNT_PRIMING);
+				$sql .= "', bottle_carbonation_temp='" . floatval($recipe->CARBONATION_TEMP);
 			}
 			if ($recipe->AMOUNT_KEGGED && $recipe->AMOUNT_PRIMING_KEGS) {
-				$psql .= "', keg_amount='" . floatval($recipe->AMOUNT_KEGGED);
-				$psql .= "', keg_carbonation='" . floatval($recipe->CARBONATION); // Lijkt wel hetzelfde als bottles
-				$psql .= "', keg_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_KEGS);
-				$psql .= "', keg_priming_amount='" . floatval($recipe->AMOUNT_PRIMING_KEGS);
-				$psql .= "', keg_carbonation_temp='" . floatval($recipe->KEG_CARB_TEMP);
-				($recipe->FORCED_CARB_KEGS == 'TRUE') ? $psql .= "', keg_forced_carb='1" : $psql .= "', keg_forced_carb='0";
-				$psql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE);
-				$psql .= "', keg_priming_factor='" . floatval($recipe->KEG_PRIMING_FACTOR);
+				$sql .= "', keg_amount='" . floatval($recipe->AMOUNT_KEGGED);
+				$sql .= "', keg_carbonation='" . floatval($recipe->CARBONATION); // Lijkt wel hetzelfde als bottles
+				$sql .= "', keg_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_KEGS);
+				$sql .= "', keg_priming_amount='" . floatval($recipe->AMOUNT_PRIMING_KEGS);
+				$sql .= "', keg_carbonation_temp='" . floatval($recipe->KEG_CARB_TEMP);
+				($recipe->FORCED_CARB_KEGS == 'TRUE') ? $sql .= "', keg_forced_carb='1" : $sql .= "', keg_forced_carb='0";
+				$sql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE);
+				$sql .= "', keg_priming_factor='" . floatval($recipe->KEG_PRIMING_FACTOR);
 			}
 		}
 
 		if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE && ($stageno >= 9)) {
 			$stage = "Ready";	// Ready if tasted.
 			$stageno = 10;
-			$psql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES);
-			$psql .= "', taste_rate='" . floatval($recipe->TASTING_RATE);
+			$sql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES);
+			$sql .= "', taste_rate='" . floatval($recipe->TASTING_RATE);
 			$tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2);
-			$psql .= "', taste_date='" . $tdate;
-			$psql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR);
-			$psql .= "', taste_transparency='" . mysqli_real_escape_string($db, $recipe->TASTE_TRANSPARENCY);
-			$psql .= "', taste_head='" . mysqli_real_escape_string($db, $recipe->TASTE_HEAD);
-			$psql .= "', taste_aroma='" . mysqli_real_escape_string($db, $recipe->TASTE_AROMA);
-			$psql .= "', taste_taste='" . mysqli_real_escape_string($db, $recipe->TASTE_TASTE);
-			$psql .= "', taste_mouthfeel='" . mysqli_real_escape_string($db, $recipe->TASTE_MOUTHFEEL);
-			$psql .= "', taste_aftertaste='" . mysqli_real_escape_string($db, $recipe->TASTE_AFTERTASTE);
+			$sql .= "', taste_date='" . $tdate;
+			$sql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR);
+			$sql .= "', taste_transparency='" . mysqli_real_escape_string($db, $recipe->TASTE_TRANSPARENCY);
+			$sql .= "', taste_head='" . mysqli_real_escape_string($db, $recipe->TASTE_HEAD);
+			$sql .= "', taste_aroma='" . mysqli_real_escape_string($db, $recipe->TASTE_AROMA);
+			$sql .= "', taste_taste='" . mysqli_real_escape_string($db, $recipe->TASTE_TASTE);
+			$sql .= "', taste_mouthfeel='" . mysqli_real_escape_string($db, $recipe->TASTE_MOUTHFEEL);
+			$sql .= "', taste_aftertaste='" . mysqli_real_escape_string($db, $recipe->TASTE_AFTERTASTE);
 		}
 
-		($recipe->INVENTORY_REDUCED == 'TRUE') ? $psql .= "', inventory_reduced='1" : $psql .= "', inventory_reduced='0";
+		($recipe->INVENTORY_REDUCED == 'TRUE') ? $sql .= "', inventory_reduced='1" : $sql .= "', inventory_reduced='0";
 		if (($recipe->LOCKED == 'TRUE') && ($stage == 'Ready')) {
-			$psql .= "', plocked='1";
-			$rsql .= "', locked='1";
+			$sql .= "', locked='1";
 			$stage = "Closed";
 			$stageno = 11;
 		} else {
-			$psql .= "', plocked='0";
-			$rsql .= "', locked='0";
+			$sql .= "', locked='0";
 		}
 
-		$psql .= "', stage='" . $stage;
+		$sql .= "', stage='" . $stage;
 //		echo ' '.$brewdate.' '.$recipe->NR_RECIPE.' '.$stage . PHP_EOL;
 
-		$rsql .= "';";
-		if (! $rresult = mysqli_query($db, $rsql)) {
-			printf("Error: %s\n", mysqli_error($db));
-		}
-
-		$psql .= "';";
-		if (! $presult = mysqli_query($db, $psql)) {
+		$sql .= "';";
+		if (! $rresult = mysqli_query($db, $sql)) {
 			printf("Error: %s\n", mysqli_error($db));
 		}
         }

mercurial