diff -r 99c02fa797f9 -r 4b157d7a1cee www/import/from_brouwhulp.php --- a/www/import/from_brouwhulp.php Sat Aug 18 14:21:21 2018 +0200 +++ b/www/import/from_brouwhulp.php Sat Aug 18 17:31:11 2018 +0200 @@ -380,10 +380,6 @@ global $brouwhulp, $db; echo " Start adding mash profiles to the database\n"; - $sql = "TRUNCATE TABLE inventory_mash_steps;"; - if (! $result = mysqli_query($db, $sql)) { - printf("Error: %s\n", mysqli_error($db)); - } $sql = "TRUNCATE TABLE inventory_mash_profiles;"; if (! $result = mysqli_query($db, $sql)) { printf("Error: %s\n", mysqli_error($db)); @@ -408,43 +404,42 @@ if ($mash->TUN_SPECIFIX_HEAT) $sql .= "', tun_specific_heat='" . $mash->TUN_SPECIFIC_HEAT; ($mash->EQUIP_ADJUST == 'TRUE') ? $sql .= "', equip_adjust='1" : $sql .= "', equip_adjust='0"; - $sql .= "';"; - /* - * Store the record and get the record number that is created. - * Store that as a reference in the steps. - */ - if (! $result = mysqli_query($db, $sql)) { - printf("Error: %s\n", mysqli_error($db)); - } - $record = mysqli_insert_id($db); /* - * Put the steps in a different table with a reference to the profile. + * Put the steps in a json array */ if ($mash->MASH_STEPS) { + $steps = "["; + $comma = FALSE; foreach ($mash->MASH_STEPS->MASH_STEP as $step) { - $sql = "INSERT INTO inventory_mash_steps SET name='" . mysqli_real_escape_string($db, $step->NAME); - $sql .= "', rec_mash_profile='" . $record; - if ($step->TYPE) - $sql .= "', type='" . $step->TYPE; - if ($step->INFUSE_AMOUNT) - $sql .= "', infuse_amount='" . $step->INFUSE_AMOUNT; - if ($step->STEP_TEMP) - $sql .= "', step_temp='" . $step->STEP_TEMP; - if ($step->STEP_TIME) - $sql .= "', step_time='" . $step->STEP_TIME; - if ($step->RAMP_TIME) - $sql .= "', ramp_time='" . $step->RAMP_TIME; - if ($step->END_TEMP) - $sql .= "', end_temp='" . $step->END_TEMP; - if ($step->DESCRIPTION) - $sql .= "', description='" . mysqli_real_escape_string($db, $step->DESCRIPTION); - $sql .= "';"; - if (! $result = mysqli_query($db, $sql)) { - printf("Error: %s\n", mysqli_error($db)); + if ($comma) + $steps .= ','; + $comma = TRUE; + $steps .= '{"name":"' . mysqli_real_escape_string($db, $step->NAME) . '"'; + if ($step->TYPE) { + $steps .= ',"type":"' . $step->TYPE . '"'; + } + if ($step->STEP_TEMP) { + $steps .= ',"step_temp":"' . $step->STEP_TEMP . '"'; + } + if ($step->STEP_TIME) { + $steps .= ',"step_time":"' . $step->STEP_TIME . '"'; } + if ($step->RAMP_TIME) { + $steps .= ',"ramp_time":"' . $step->RAMP_TIME . '"'; + } + if ($step->END_TEMP) { + $steps .= ',"end_temp":"' . $step->END_TEMP . '"'; + } + $steps .= "}"; } + $steps .= ']'; + $sql .= "', steps='" . $steps; + } + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); } } } @@ -455,10 +450,10 @@ //do_hops(); //do_yeasts(); //do_miscs(); -do_waters(); +//do_waters(); //do_equipments(); //do_styles(); -//do_mash(); +do_mash(); mysqli_close($db);