Adjusted product save into the database.

Sun, 03 Feb 2019 23:13:16 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 03 Feb 2019 23:13:16 +0100
changeset 238
8e7384587a10
parent 237
9337b5ff8698
child 239
03e81378182d

Adjusted product save into the database.

www/includes/db_product.php file | annotate | diff | comparison | revisions
--- a/www/includes/db_product.php	Sun Feb 03 21:26:23 2019 +0100
+++ b/www/includes/db_product.php	Sun Feb 03 23:13:16 2019 +0100
@@ -51,7 +51,7 @@
 	$sql .= "', eq_tun_volume='" . $_POST['eq_tun_volume'];
 	$sql .= "', eq_tun_weight='" . $_POST['eq_tun_weight'];
 	$sql .= "', eq_tun_specific_heat='" . $_POST['eq_tun_specific_heat'];
-	$sql .= "', eq_tun_material='" . mysqli_real_escape_string($connect, $_POST['eq_tun_material']);
+	$sql .= "', eq_tun_material='" . $_POST['eq_tun_material'];
 	$sql .= "', eq_tun_height='" . $_POST['eq_tun_height'];
 	$sql .= "', eq_top_up_water='" . $_POST['eq_top_up_water'];
 	$sql .= "', eq_trub_chiller_loss='" . $_POST['eq_trub_chiller_loss'];
@@ -138,7 +138,7 @@
 	$sql .= "', st_name='" . mysqli_real_escape_string($connect, $_POST['st_name']);
 	$sql .= "', st_letter='" . mysqli_real_escape_string($connect, $_POST['st_letter']);
 	$sql .= "', st_guide='" . mysqli_real_escape_string($connect, $_POST['st_guide']);
-	$sql .= "', st_type='" . mysqli_real_escape_string($connect, $_POST['st_type']);
+	$sql .= "', st_type='" . $_POST['st_type'];
 	$sql .= "', st_category='" . mysqli_real_escape_string($connect, $_POST['st_category']);
 	$sql .= "', st_category_number='" . $_POST['st_category_number'];
 	$sql .= "', st_og_min='" . $_POST['st_og_min'];
@@ -200,62 +200,157 @@
 		$sql .= "', w2_ph='" . $_POST['w2_ph'];
 		$sql .= "', w2_cost='" . $_POST['w2_cost'];
 	}
+	$sql .= "', wa_acid_name='" . $_POST['wa_acid_name'];
+	$sql .= "', wa_acid_perc='" . $_POST['wa_acid_perc'];
+	$sql .= "', wa_base_name='" . $_POST['wa_base_name'];
 	syslog(LOG_NOTICE, $sql);
 
+	$fermentables = '[';
+	$comma = FALSE;
 	if (isset($_POST['fermentables'])) {
 		$array = $_POST['fermentables'];
 		foreach($array as $key => $item){
-			foreach ($disallowed as $disallowed_key) {
-				unset($array[$key]["$disallowed_key"]);
-			}
+			/*
+			 * Manual encode to json.
+			 */
+			if ($comma)
+				$fermentables .= ',';
+			$comma = TRUE;
+			$fermentable  = '{"f_name":"' . str_replace($rescapers,$rreplacements,$item['f_name']);
+			$fermentable .= '","f_origin":"' . str_replace($rescapers,$rreplacements,$item['f_origin']);
+			$fermentable .= '","f_supplier":"' . str_replace($rescapers,$rreplacements,$item['f_supplier']);
+			$fermentable .= '","f_amount":' . $item['f_amount'];
+			$fermentable .= ',"f_cost":' . $item['f_cost'];
+			$fermentable .= ',"f_type":' . $item['f_type'];
+			$fermentable .= ',"f_yield":' . $item['f_yield'];
+			$fermentable .= ',"f_color":' . $item['f_color'];
+			$fermentable .= ',"f_coarse_fine_diff":' . $item['f_coarse_fine_diff'];
+			$fermentable .= ',"f_moisture":' . $item['f_moisture'];
+			$fermentable .= ',"f_diastatic_power":' . $item['f_diastatic_power'];
+			$fermentable .= ',"f_protein":' . $item['f_protein'];
+			$fermentable .= ',"f_dissolved_protein":' . $item['f_dissolved_protein'];
+			$fermentable .= ',"f_max_in_batch":' . $item['f_max_in_batch'];
+			$fermentable .= ',"f_graintype":' . $item['f_graintype'];
+			$fermentable .= ',"f_added":' . $item['f_added'];
+			$fermentable .= ',"f_recommend_mash":' . $item['f_recommend_mash'];
+			$fermentable .= ',"f_add_after_boil":' . $item['f_add_after_boil'];
+			$fermentable .= ',"f_adjust_to_total_100":' . $item['f_adjust_to_total_100'];
+			$fermentable .= ',"f_percentage":' . $item['f_percentage'];
+			$fermentable .= ',"f_di_ph":' . $item['f_di_ph'];
+			$fermentable .= ',"f_acid_to_ph_57":' . $item['f_acid_to_ph_57'] . '}';
+			syslog(LOG_NOTICE, $fermentable);
+			$fermentables .= $fermentable;
 		}
-//		syslog(LOG_NOTICE, "json_fermentables=: ".str_replace($rescapers,$rreplacements,json_encode($array)));
-		$sql .= "', json_fermentables='" . str_replace($rescapers,$rreplacements,json_encode($array));
 	}
+	$fermentables .= ']';
+	$sql .= "', json_fermentables='" . $fermentables;
 
+	$hops = '[';
+	$comma = FALSE;
 	if (isset($_POST['hops'])) {
 		$array = $_POST['hops'];
 		foreach($array as $key => $item){
-			foreach ($disallowed as $disallowed_key) {
-				unset($array[$key]["$disallowed_key"]);
-			}
+			if ($comma)
+				$hops .= ',';
+			$comma = TRUE;
+			$hop  = '{"h_name":"' . str_replace($rescapers,$rreplacements,$item['h_name']);
+			$hop .= '","h_origin":"' . str_replace($rescapers,$rreplacements,$item['h_origin']);
+			$hop .= '","h_amount":' . $item['h_amount'];
+			$hop .= ',"h_cost":' . $item['h_cost'];
+			$hop .= ',"h_type":' . $item['h_type'];
+			$hop .= ',"h_form":' . $item['h_form'];
+			$hop .= ',"h_useat":' . $item['h_useat'];
+			$hop .= ',"h_time":' . $item['h_time'];
+			$hop .= ',"h_alpha":' . $item['h_alpha'];
+			$hop .= ',"h_beta":' . $item['h_beta'];
+			$hop .= ',"h_hsi":' . $item['h_hsi'];
+			$hop .= ',"h_humulene":' . $item['h_humulene'];
+			$hop .= ',"h_caryophyllene":' . $item['h_caryophyllene'];
+			$hop .= ',"h_cohumulone":' . $item['h_cohumulone'];
+			$hop .= ',"h_myrcene":' . $item['h_myrcene'];
+			$hop .= ',"h_total_oil":' . $item['h_total_oil'] . '}';
+			syslog(LOG_NOTICE, $hop);
+			$hops .= $hop;
 		}
-//		syslog(LOG_NOTICE, "json_hops: ".str_replace($rescapers,$rreplacements,json_encode($array)));
-		$sql .= "', json_hops='" . str_replace($rescapers,$rreplacements,json_encode($array));
 	}
+	$hops .= ']';
+	$sql .= "', json_hops='" . $hops;
 
+	$miscs = '[';
+	$comma = FALSE;
 	if (isset($_POST['miscs'])) {
 		$array = $_POST['miscs'];
-		foreach($array as $key => $item){ 
-			foreach ($disallowed as $disallowed_key) {
-				unset($array[$key]["$disallowed_key"]);
-			}
+		foreach($array as $key => $item){
+			if ($comma)
+				$miscs .= ',';
+			$comma = TRUE;
+			$misc  = '{"m_name":"' . str_replace($rescapers,$rreplacements,$item['m_name']);
+			$misc .= '","m_amount":' . $item['m_amount'];
+			$misc .= ',"m_type":' . $item['m_type'];
+			$misc .= ',"m_use_use":' . $item['m_use_use'];
+			$misc .= ',"m_time":' . $item['m_time'];
+			$misc .= ',"m_amount_is_weight":' . $item['m_amount_is_weight'];
+			$misc .= ',"m_cost":' . $item['m_cost'] . '}';
+			syslog(LOG_NOTICE, $misc);
+			$miscs .= $misc;
 		}
-//		syslog(LOG_NOTICE, "json_miscs: ".str_replace($rescapers,$rreplacements,json_encode($array)));
-		$sql .= "', json_miscs='" . str_replace($rescapers,$rreplacements,json_encode($array));
 	}
+	$miscs .= ']';
+	$sql .= "', json_miscs='" . $miscs;
 
+	$yeasts = '[';
+	$comma = FALSE;
 	if (isset($_POST['yeasts'])) {
 		$array = $_POST['yeasts'];
 		foreach($array as $key => $item){
-			foreach ($disallowed as $disallowed_key) {
-				unset($array[$key]["$disallowed_key"]);
-			}
+			if ($comma)
+				$yeasts .= ',';
+			$comma = TRUE;
+			$yeast  = '{"y_name":"' . str_replace($rescapers,$rreplacements,$item['y_name']);
+			$yeast .= '","y_laboratory":"' . str_replace($rescapers,$rreplacements,$item['y_laboratory']);
+			$yeast .= '","y_product_id":"' . str_replace($rescapers,$rreplacements,$item['y_product_id']);
+			$yeast .= '","y_amount":' . $item['y_amount'];
+			$yeast .= ',"y_type":' . $item['y_type'];
+			$yeast .= ',"y_form":' . $item['y_form'];
+			$yeast .= ',"y_min_temperature":' . $item['y_min_temperature'];
+			$yeast .= ',"y_max_temperature":' . $item['y_max_temperature'];
+			$yeast .= ',"y_flocculation":' . $item['y_flocculation'];
+			$yeast .= ',"y_attenuation":' . $item['y_attenuation'];
+			$yeast .= ',"y_cells":' . $item['y_cells'];
+			$yeast .= ',"y_inventory":' . $item['y_inventory'];
+			$yeast .= ',"y_use":' . $item['y_use'];
+			$yeast .= ',"y_cost":' . $item['y_cost'] . '}';
+			syslog(LOG_NOTICE, $yeast);
+			$yeasts .= $yeast;
 		}
-//		syslog(LOG_NOTICE, "json_yeasts: ". str_replace($rescapers,$rreplacements,json_encode($array)));
-		$sql .= "', json_yeasts='" . str_replace($rescapers,$rreplacements,json_encode($array));
 	}
+	$yeasts .= ']';
+	$sql .= "', json_yeasts='" . $yeasts;
 
+	$mashs = '[';
+	$comma = FALSE;
 	if (isset($_POST['mashs'])) {
 		$array = $_POST['mashs'];
 		foreach($array as $key => $item){
-			foreach ($disallowed as $disallowed_key) {
-				unset($array[$key]["$disallowed_key"]);
-			}
+			if ($comma)
+				$mashs .= ',';
+			$comma = TRUE;
+			$mash  = '{"step_name":"' . str_replace($rescapers,$rreplacements,$item['step_name']);
+			$mash .= '","step_type":' . $item['step_type'];
+			if (isset($item['step_infuse_amount']) && $item['step_infuse_amount'] != "")
+				$mash .= ',"step_infuse_amount":' . $item['step_infuse_amount'];
+			else
+				$mash .= ',"step_infuse_amount":0';
+			$mash .= ',"step_temp":' . $item['step_temp'];
+			$mash .= ',"step_time":' . $item['step_time'];
+			$mash .= ',"ramp_time":' . $item['ramp_time'];
+			$mash .= ',"end_temp":' . $item['end_temp'] . '}';
+			syslog(LOG_NOTICE, $mash);
+			$mashs .= $mash;
 		}
-//		syslog(LOG_NOTICE, "json_mashs: ".str_replace($rescapers,$rreplacements,json_encode($array)));
-		$sql .= "', json_mashs='" . str_replace($rescapers,$rreplacements,json_encode($array));
 	}
+	$mashs .= ']';
+	$sql .= "', json_mashs='" . $mashs;
 
 	if (isset($_POST['insert'])) {
 		$sql .= "';";

mercurial