Tue, 31 Aug 2021 20:48:37 +0200
Split batch, adjust mash step volume. In the duplicated log_brew handle the missing values. In save product, round the mash step sg to 4 decimals. In prod_edit, ingredients are stored as strings, not arrays. This triggered a memory corruption that only happened in rare circumstances. Don't fix mash step fields in the javascript, it is already done during load from the database. Calculation of the mash volume is rounded to 6 decimals. Enter mash step Brix/Plato value, the SG result is rounded to 4 decimals.
<?php require_once('config.php'); require("version.php"); require("includes/formulas.php"); $target_dir = "tmp/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if file already exists if (file_exists($target_file)) { echo "Fout 1: bestand bestaat al. "; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) { echo "Fout 2: het bestand is te groot. "; $uploadOk = 0; } // Allow certain file formats if ($imageFileType != "xml" && $uploadOk) { echo "Fout 3: alleen XML bestanden toegestaan. "; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { exit; } if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />"; } else { echo "Fout 4: er ging iets fout met de upload."; exit; } $db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); if (! $db) { echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error(); exit; } mysqli_set_charset($db, "utf8" ); date_default_timezone_set('Europe/Amsterdam'); $imported = 0; $yeasts = simplexml_load_file($target_file); foreach ($yeasts->YEAST as $yeast) { $sql = "INSERT INTO inventory_yeasts SET name='" . mysqli_real_escape_string($db, $yeast->NAME); if ($yeast->TYPE == 'Lager') $sql .= "', type='0"; else if ($yeast->TYPE == 'Ale') $sql .= "', type='1"; else if ($yeast->TYPE == 'Wheat') $sql .= "', type='2"; else if ($yeast->TYPE == 'Wine') $sql .= "', type='3"; else if ($yeast->TYPE == 'Champagne') $sql .= "', type='4"; else echo "Unknown TYPE " . $yeast->TYPE . "<br />"; if ($yeast->FORM == 'Liquid') $sql .= "', form='0"; else if ($yeast->FORM == 'Dry') $sql .= "', form='1"; else if ($yeast->FORM == 'Slant') $sql .= "', form='2"; else if ($yeast->FORM == 'Culture') $sql .= "', form='3"; else if ($yeast->FORM == 'Frozen') $sql .= "', form='4"; else if ($yeast->FORM == 'Bottle') $sql .= "', form='5"; else echo "Unknown FORM " . $yeast->FORM . "<br />"; $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='" . floatval($yeast->MIN_TEMPERATURE); if ($yeast->MAX_TEMPERATURE) $sql .= "', max_temperature='" . floatval($yeast->MAX_TEMPERATURE); if ($yeast->FLOCCULATION == 'Low') $sql .= "', flocculation='0"; else if ($yeast->FLOCCULATION == 'Medium') $sql .= "', flocculation='1"; else if ($yeast->FLOCCULATION == 'High') $sql .= "', flocculation='2"; else if ($yeast->FLOCCULATION == 'Very high') $sql .= "', flocculation='3"; else echo "Unknown FLOCCULATION " . $yeast->FLOCCULATION . PHP_EOL; if ($yeast->ATTENUATION) $sql .= "', attenuation='" . floatval($yeast->ATTENUATION); $sql .= "', notes='" . mysqli_real_escape_string($db, $yeast->NOTES); $sql .= "', best_for='" . mysqli_real_escape_string($db, $yeast->BEST_FOR); if ($yeast->MAX_REUSE) $sql .= "', max_reuse='" . $yeast->MAX_REUSE; if ($yeast->FORM == 'Liquid') { if ($yeast->LABORATORY == 'Imperial Yeast') $sql .= "', cells='200000000000"; // 200 billion cells per pack else $sql .= "', cells='100000000000"; // 100 billion cells per pack if ($yeast->COST) $sql .= "', cost='" . floatval($yeast->COST); if ($yeast->INVENTORY) $sql .= "', inventory='" . floatval($yeast->INVENTORY); } else if ($yeast->FORM == 'Dry') { $sql .= "', cells='15000000000"; // 6..15 billion per gram if ($yeast->INVENTORY) $sql .= "', inventory='" . floatval($yeast->INVENTORY) / 1000.0; // To kg if ($yeast->COST) $sql .= "', cost='" . floatval($yeast->COST) * 1000.0; // to Euro/kg } else { $sql .= "', cells='1700000000"; // 1.7 billion cells per ml. if ($yeast->INVENTORY) $sql .= "', inventory='" . floatval($yeast->INVENTORY) / 1000.0; // To liter if ($yeast->COST) $sql .= "', cost='" . floatval($yeast->COST) * 1000.0; // to Euro/liter } 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)) { echo "Fout 8: " . mysqli_error($db) . "<br />"; } else { echo "+ " . $yeast->NAME . "<br />"; $imported++; } } if ($imported == 0) { echo "Fout 7: geen gisten in dit bestand.<br />"; } else { echo $imported . " gisten toegevoegd.<br />"; } // Don't clutter the upload directory. unlink($target_file); ?>