Tue, 10 Dec 2019 20:11:37 +0100
Fix upgrade of the yeast data in products and recipes if the original yeast is not found. Export product or recipe for forum is now coded in forum format and copied to the clipboard ready to paste on a forum.
<?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; $styles = simplexml_load_file($target_file); foreach ($styles->STYLE as $style) { $sql = "INSERT INTO profile_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); if ($style->TYPE == 'Lager') $sql .= "', type='0"; else if ($style->TYPE == 'Ale') $sql .= "', type='1"; else if ($style->TYPE == 'Mead') $sql .= "', type='2"; else if ($style->TYPE == 'Wheat') $sql .= "', type='3"; else if ($style->TYPE == 'Mixed') $sql .= "', type='4"; else if ($style->TYPE == 'Cider') $sql .= "', type='5"; else echo "Unknown TYPE " . $style->TYPE . "<br />"; $sql .= "', og_min='" . floatval($style->OG_MIN); $sql .= "', og_max='" . floatval($style->OG_MAX); $sql .= "', fg_min='" . floatval($style->FG_MIN); $sql .= "', fg_max='" . floatval($style->FG_MAX); $sql .= "', ibu_min='" . floatval($style->IBU_MIN); $sql .= "', ibu_max='" . floatval($style->IBU_MAX); $sql .= "', color_min='" . srm_to_ebc(floatval($style->COLOR_MIN)); $sql .= "', color_max='" . srm_to_ebc(floatval($style->COLOR_MAX)); $sql .= "', carb_min='" . floatval($style->CARB_MIN); $sql .= "', carb_max='" . floatval($style->CARB_MAX); $sql .= "', abv_min='" . floatval($style->ABV_MIN); $sql .= "', abv_max='" . floatval($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)) { echo "Fout 8: " . mysqli_error($db) . "<br />"; } else { echo "+ " . $style->NAME . "<br />"; $imported++; } } if ($imported == 0) { echo "Fout 7: geen stylen in dit bestand.<br />"; } else { echo $imported . " stylen toegevoegd.<br />"; } // Don't clutter the upload directory. unlink($target_file); ?>