diff -r 606b4af8f918 -r d341f0a91a91 www/import/from_brouwhulp.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/import/from_brouwhulp.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,461 @@ +FERMENTABLE as $fermentable) { + + $sql = "INSERT INTO inventory_fermentables SET name='" . mysqli_real_escape_string($db, $fermentable->NAME); + $sql .= "', type='" . $fermentable->TYPE; + if ($fermentable->YIELD) + $sql .= "', yield='" . $fermentable->YIELD; + if ($fermentable->COLOR) { + $srm = $fermentable->COLOR; + $ebc = srm_to_ebc($srm); + if ($ebc < 0) + $ebc = 0; + $nsrm = ebc_to_srm($ebc); + echo 'SRM '.$srm.' EBC '.$ebc.' back '.$nsrm.PHP_EOL; + $sql .= "', color='" . $ebc; + } + ($fermentable->ADD_AFTER_BOIL == "TRUE") ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; + $sql .= "', origin='" . mysqli_real_escape_string($db, $fermentable->ORIGIN); + $sql .= "', supplier='" . mysqli_real_escape_string($db, $fermentable->SUPPLIER); + $sql .= "', notes='" . mysqli_real_escape_string($db, $fermentable->NOTES); + if ($fermentable->COARSE_FINE_DIFF) + $sql .= "', coarse_fine_diff='" . $fermentable->COARSE_FINE_DIFF; + if ($fermentable->MOISTURE) + $sql .= "', moisture='" . $fermentable->MOISTURE; + if ($fermentable->DIASTATIC_POWER) + $sql .= "', diastatic_power='" . $fermentable->DIASTATIC_POWER; + if ($fermentable->PROTEIN) + $sql .= "', protein='" . $fermentable->PROTEIN; + if ($fermentable->MAX_IN_BATCH) + $sql .= "', max_in_batch='" . $fermentable->MAX_IN_BATCH; + ($fermentable->RECOMMEND_MASH == "TRUE") ? $sql .= "', recommend_mash='Y" : $sql .= "', recommend_mash='N"; + if ($fermentable->IBU_GAL_PER_LB) + $sql .= "', ibu_gal_per_lb='" . $fermentable->IBU_GAL_PER_LB; + ($fermentable->ALWAYS_ON_STOCK == "TRUE") ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($fermentable->INVENTORY) + $sql .= "', inventory='" . $fermentable->INVENTORY; + if ($fermentable->COST) + $sql .= "', cost='" . $fermentable->COST; + /* + * These are not beerxml standard: + */ + if ($fermentable->DI_pH) + $sql .= "', di_ph='" . $fermentable->DI_pH; + if ($fermentable->{'ACID_TO_pH_5.7'}) + $sql .= "', acid_to_ph_57='" . $fermentable->{'ACID_TO_pH_5.7'}; + $sql .= "', graintype='" . $fermentable->GRAINTYPE; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + +function do_hops() +{ + global $brouwhulp, $db; + + echo " Start adding hops to the database\n"; + $sql = "TRUNCATE TABLE inventory_hops;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $myhops = simplexml_load_file($brouwhulp . '/hops.xml'); + + foreach ($myhops->HOP as $hop) { + + $sql = "INSERT INTO inventory_hops SET name='" . mysqli_real_escape_string($db, $hop->NAME); + if ($hop->ALPHA) + $sql .= "', alpha='" . $hop->ALPHA; + if ($hop->BETA) + $sql .= "', beta='" . $hop->BETA; + if ($hop->HUMULENE) + $sql .= "', humulene='" . $hop->HUMULENE; + if ($hop->CARYOPHYLLENE) + $sql .= "', caryophyllene='" . $hop->CARYOPHYLLENE; + if ($hop->COHUMULONE) + $sql .= "', cohumulone='" . $hop->COHUMULONE; + if ($hop->MYCRENE) + $sql .= "', myrcene='" . $hop->MYCRENE; + if ($hop->HSI) + $sql .= "', hsi='" . $hop->HSI; + $sql .= "', useat='" . $hop->USE; + $sql .= "', type='" . $hop->TYPE; + $sql .= "', form='" . $hop->FORM; + $sql .= "', notes='" . mysqli_real_escape_string($db, $hop->NOTES); + $sql .= "', origin='" . mysqli_real_escape_string($db, $hop->ORIGIN); + $sql .= "', substitutes='" . mysqli_real_escape_string($db, $hop->SUBSTITUTES); + ($hop->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($hop->INVENTORY) + $sql .= "', inventory='" . $hop->INVENTORY; + if ($hop->COST) + $sql .= "', cost='" . $hop->COST; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } + +} + + + +function do_yeasts() +{ + global $brouwhulp, $db; + + echo " Start adding yeasts to the database\n"; + $sql = "TRUNCATE TABLE inventory_yeasts;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $yeasts = simplexml_load_file($brouwhulp . '/yeasts.xml'); + + foreach ($yeasts->YEAST as $yeast) { + + $sql = "INSERT INTO inventory_yeasts SET name='" . mysqli_real_escape_string($db, $yeast->NAME); + $sql .= "', type='" . $yeast->TYPE; + $sql .= "', form='" . $yeast->FORM; + if ($yeast->AMOUNT) + $sql .= "', amount='" . $yeast->AMOUNT; + ($yeast->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='Y" : $sql .= "', amount_is_weight='N"; + $sql .= "', laboratory='" . mysqli_real_escape_string($db, $yeast->LABORATORY); + $sql .= "', product_id='" . mysqli_real_escape_string($db, $yeast->PRODUCT_ID); + if ($yeast->MIN_TEMPERATURE) + $sql .= "', min_temperature='" . $yeast->MIN_TEMPERATURE; + if ($yeast->MAX_TEMPERATURE) + $sql .= "', max_temperature='" . $yeast->MAX_TEMPERATURE; + $sql .= "', flocculation='" . $yeast->FLOCCULATION; + if ($yeast->ATTENUATION) + $sql .= "', attenuation='" . $yeast->ATTENUATION; + $sql .= "', notes='" . mysqli_real_escape_string($db, $yeast->NOTES); + $sql .= "', best_for='" . mysqli_real_escape_string($db, $yeast->BEST_FOR); + if ($yeast->TIMES_CULTURED) + $sql .= "', times_cultured='" . $yeast->TIMES_CULTURED; + if ($yeast->MAX_REUSE) + $sql .= "', max_reuse='" . $yeast->MAX_REUSE; + if ($yeast->INVENTORY) + $sql .= "', inventory='" . $yeast->INVENTORY; + if ($yeast->COST) + $sql .= "', cost='" . $yeast->COST; + if ($yeast->CULTURE_DATE) { + $date = substr($yeast->CULTURE_DATE, 6, 4) . '-' . substr($yeast->CULTURE_DATE, 3, 2) . '-' . substr($yeast->CULTURE_DATE, 0, 2); + $sql .= "', production_date='" . $date; + } + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_waters() +{ + global $brouwhulp, $db; + + echo " Start adding waters to the database\n"; + $sql = "TRUNCATE TABLE inventory_water_profiles;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $waters = simplexml_load_file($brouwhulp . '/waters.xml'); + + foreach ($waters->WATER as $water) { + + $sql = "INSERT INTO inventory_water_profiles SET name='" . mysqli_real_escape_string($db, $water->NAME); + ($water->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($water->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $water->NOTES); + $sql .= "', calcium='" . $water->CALCIUM; + $sql .= "', bicarbonate='" . $water->BICARBONATE; + $sql .= "', sulfate='" . $water->SULFATE; + $sql .= "', chloride='" . $water->CHLORIDE; + $sql .= "', sodium='" . $water->SODIUM; + $sql .= "', magnesium='" . $water->MAGNESIUM; + $sql .= "', ph='" . $water->PH; + if ($water->TOTAL_ALKALINITY) + $sql .= "', total_alkalinity='" . $water->TOTAL_ALKALINITY; + ($water->DEFAULT_WATER == 'TRUE') ? $sql .= "', default_water='Y" : $sql .= "', default_water='N"; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_miscs() +{ + global $brouwhulp, $db; + + echo " Start adding miscs to the database\n"; + $sql = "TRUNCATE TABLE inventory_miscs;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $miscs = simplexml_load_file($brouwhulp . '/miscs.xml'); + + foreach ($miscs->MISC as $misc) { + + $sql = "INSERT INTO inventory_miscs SET name='" . mysqli_real_escape_string($db, $misc->NAME); + if ($misc->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $misc->NOTES); + $sql .= "', type='" . $misc->TYPE; + $sql .= "', use_use='" . $misc->USE; + $sql .= "', time='" . $misc->TIME; + $sql .= "', amount='" . $misc->AMOUNT; + ($misc->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='Y" : $sql .= "', amount_is_weight='N"; + if ($misc->USE_FOR) + $sql .= "', use_for='" . mysqli_real_escape_string($db, $misc->USE_FOR); + if ($misc->ALWAYS_ON_STOCK) + ($misc->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($misc->INVENTORY) + $sql .= "', inventory='" . $misc->INVENTORY; + if ($misc->COST) + $sql .= "', cost='" . $misc->COST; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_equipments() +{ + global $brouwhulp, $db; + + echo " Start adding equipments to the database\n"; + $sql = "TRUNCATE TABLE inventory_equipments;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $equipments = simplexml_load_file($brouwhulp . '/equipments.xml'); + + foreach ($equipments->EQUIPMENT as $equipment) { + + $sql = "INSERT INTO inventory_equipments SET name='" . mysqli_real_escape_string($db, $equipment->NAME); + $sql .= "', boil_size='" . $equipment->BOIL_SIZE; + $sql .= "', batch_size='" . $equipment->BATCH_SIZE; + $sql .= "', tun_volume='" . $equipment->TUN_VOLUME; + $sql .= "', tun_weight='" . $equipment->TUN_WEIGHT; + $sql .= "', tun_specific_heat='" . $equipment->TUN_SPECIFIC_HEAT; + $sql .= "', top_up_water='" . $equipment->TOP_UP_WATER; + $sql .= "', trub_chiller_loss='" . $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. + */ + $sql .= "', evap_rate='" . ($equipment->EVAP_RATE * $equipment->BOIL_SIZE) / 100.0; + $sql .= "', boil_time='" . $equipment->BOIL_TIME; + ($equipment->CALC_BOIL_VOLUME == 'TRUE') ? $sql .= "', calc_boil_volume='Y" : $sql .= "', calc_boil_volume='N"; + $sql .= "', lauter_deadspace='" . $equipment->LAUTER_DEADSPACE; + $sql .= "', top_up_kettle='" . $equipment->TOP_UP_KETTLE; + $sql .= "', hop_utilization='" . $equipment->HOP_UTILIZATION; + if ($equipment->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $equipment->NOTES); + $sql .= "', lauter_volume='" . $equipment->LAUTER_VOLUME; + $sql .= "', kettle_volume='" . $equipment->KETTLE_VOLUME; + if ($equipment->TUN_MATERIAL) + $sql .= "', tun_material='" . mysqli_real_escape_string($db, $equipment->TUN_MATERIAL); + $sql .= "', tun_height='" . $equipment->TUN_HEIGHT; + $sql .= "', kettle_height='" . $equipment->KETTLE_HEIGHT; + $sql .= "', lauter_height='" . $equipment->LAUTER_HEIGHT; + $sql .= "', mash_volume='" . $equipment->MASH_VOLUME; + $sql .= "', efficiency='" . $equipment->EFFICIENCY; + + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_styles() +{ + global $brouwhulp, $db; + + echo " Start adding styles to the database\n"; + $sql = "TRUNCATE TABLE inventory_styles;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $styles = simplexml_load_file($brouwhulp . '/styles.xml'); + + foreach ($styles->STYLE as $style) { + + $sql = "INSERT INTO inventory_styles SET name='" . mysqli_real_escape_string($db, $style->NAME); + if ($style->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $style->NOTES); + if ($style->CATEGORY) + $sql .= "', category='" . mysqli_real_escape_string($db, $style->CATEGORY); + if ($style->CATEGORY_NUMBER) + $sql .= "', category_number='" . $style->CATEGORY_NUMBER; + if ($style->STYLE_LETTER) + $sql .= "', style_letter='" . mysqli_real_escape_string($db, $style->STYLE_LETTER); + if ($style->STYLE_GUIDE) + $sql .= "', style_guide='" . mysqli_real_escape_string($db, $style->STYLE_GUIDE); + $sql .= "', type='" . $style->TYPE; + $sql .= "', og_min='" . $style->OG_MIN; + $sql .= "', og_max='" . $style->OG_MAX; + $sql .= "', fg_min='" . $style->FG_MIN; + $sql .= "', fg_max='" . $style->FG_MAX; + $sql .= "', ibu_min='" . $style->IBU_MIN; + $sql .= "', ibu_max='" . $style->IBU_MAX; + $sql .= "', color_min='" . $style->COLOR_MIN; + $sql .= "', color_max='" . $style->COLOR_MAX; + $sql .= "', carb_min='" . $style->CARB_MIN; + $sql .= "', carb_max='" . $style->CARB_MAX; + $sql .= "', abv_min='" . $style->ABV_MIN; + $sql .= "', abv_max='" . $style->ABV_MAX; + if ($style->PROFILE) + $sql .= "', profile='" . mysqli_real_escape_string($db, $style->PROFILE); + if ($style->INGREDIENTS) + $sql .= "', ingredients='" . mysqli_real_escape_string($db, $style->INGREDIENTS); + if ($style->EXAMPLES) + $sql .= "', examples='" . mysqli_real_escape_string($db, $style->EXAMPLES); + + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_mash() +{ + 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)); + } + + $mashes = simplexml_load_file($brouwhulp . '/mashs.xml'); + + foreach ($mashes->MASH as $mash) { + $sql = "INSERT INTO inventory_mash_profiles SET name='" . mysqli_real_escape_string($db, $mash->NAME); + if ($mash->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $mash->NOTES); + if ($mash->GRAIN_TEMP) + $sql .= "', grain_temp='" . $mash->GRAIN_TEMP; + if ($mash->TUN_TEMP) + $sql .= "', tun_temp='" . $mash->TUN_TEMP; + if ($mash->SPARGE_TEMP) + $sql .= "', sparge_temp='" . $mash->SPARGE_TEMP; + if ($mash->PH) + $sql .= "', ph='" . $mash->PH; + if ($mash->TUN_WEIGHT) + $sql .= "', tun_weight='" . $mash->TUN_WEIGHT; + if ($mash->TUN_SPECIFIX_HEAT) + $sql .= "', tun_specific_heat='" . $mash->TUN_SPECIFIC_HEAT; + ($mash->EQUIP_ADJUST == 'TRUE') ? $sql .= "', equip_adjust='Y" : $sql .= "', equip_adjust='N"; + $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. + */ + if ($mash->MASH_STEPS) { + 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)); + } + } + } + } +} + + + +do_fermentables(); +//do_hops(); +//do_yeasts(); +//do_waters(); +//do_miscs(); +//do_equipments(); +//do_styles(); +//do_mash(); + +mysqli_close($db); + +echo "Finished adding data\n"; + + +?>