Wed, 16 Oct 2019 21:05:03 +0200
Added dutch array strings to a global php script. Changed fermentables, hops, yeast and misc inventory scripts to use these strings between the database scripts and javascript scripts. This makes filtering on types strings useable. Added these changes to the product/recipe forum and print exports too.
<?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; $hops = simplexml_load_file($target_file); foreach ($hops->HOP as $hop) { $sql = "INSERT INTO inventory_hops SET name='" . mysqli_real_escape_string($db, $hop->NAME); if ($hop->ALPHA) $sql .= "', alpha='" . floatval($hop->ALPHA); if ($hop->BETA) $sql .= "', beta='" . floatval($hop->BETA); if ($hop->HUMULENE) $sql .= "', humulene='" . floatval($hop->HUMULENE); if ($hop->CAROPHYLLENE) $sql .= "', caryophyllene='" . floatval($hop->CAROPHYLLENE); if ($hop->COHUMULONE) $sql .= "', cohumulone='" . floatval($hop->COHUMULONE); if ($hop->MYRCENE) $sql .= "', myrcene='" . floatval($hop->MYRCENE); if ($hop->HSI) $sql .= "', hsi='" . floatval($hop->HSI); if ($hop->TYPE == 'Bittering') $sql .= "', type='0"; else if ($hop->TYPE == 'Aroma') $sql .= "', type='1"; else if ($hop->TYPE == 'Both') $sql .= "', type='2"; else echo "Unknown TYPE " . $hop->TYPE . "<br />"; if ($hop->FORM == 'Pellet') $sql .= "', form='0"; else if ($hop->FORM == 'Plug') $sql .= "', form='1"; else if ($hop->FORM == 'Leaf') $sql .= "', form='2"; else echo "Unknown FORM " . $hop->FORM . "<br />"; $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='1" : $sql .= "', always_on_stock='0"; if ($hop->INVENTORY) $sql .= "', inventory='" . floatval($hop->INVENTORY) / 1000.0; if ($hop->COST) $sql .= "', cost='" . floatval($hop->COST); if ($hop->TOTAL_OIL) $sql .= "', total_oil='" . floatval($hop->TOTAL_OIL); if ($hop->HARVEST_DATE) { $date = substr($hop->HARVEST_DATE, 6, 4).'-'.substr($hop->HARVEST_DATE, 3, 2).'-'.substr($hop->HARVEST_DATE, 0, 2); $sql .= "', production_date='" . $date; } $sql .= "';"; if (! $result = mysqli_query($db, $sql)) { echo "Fout 8: " . mysqli_error($db) . "<br />"; } else { echo "+ " . $hop->NAME . "<br />"; $imported++; } } if ($imported == 0) { echo "Fout 7: geen hoppen in dit bestand.<br />"; } else { echo $imported . " hoppen toegevoegd.<br />"; } // Don't clutter the upload directory. unlink($target_file); ?>