--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/export_yeasts.php Fri May 01 16:37:31 2020 +0200 @@ -0,0 +1,75 @@ +<?php +require_once($_SERVER['DOCUMENT_ROOT'].'/config.php'); +require_once($_SERVER['DOCUMENT_ROOT'].'/includes/formulas.php'); + + +$link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); +if (! $link) { + die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); +} +if (! mysqli_set_charset($link, "utf8" )) { + echo "error"; + return 1; +} + +$result = mysqli_query($link, "SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name"); +$row = mysqli_fetch_array($result); + +function field($x, $field, $value) { + xmlwriter_start_element($x, $field); + xmlwriter_text($x, $value); + xmlwriter_end_element($x); +} + +$yeasttype = array( 'Lager', 'Ale', 'Wheat', 'Wine', 'Champagne', 'Other', 'Other', 'Other', 'Other', 'Other' ); +$yeastform = array( 'Liquid', 'Dry', 'Slant', 'Culture', 'Frozen', 'Bottle', 'Dry' ); +$yeastflocculation = array( 'Low', 'Medium', 'High', 'Very high' ); + + +/* + * Create beerxml output + */ +$xw = xmlwriter_open_memory(); +xmlwriter_set_indent($xw, 1); +$res = xmlwriter_set_indent_string($xw, ' '); + +xmlwriter_start_document($xw, '1.0', 'UTF-8'); + + +xmlwriter_start_element($xw, 'YEASTS'); +while ($row = mysqli_fetch_array($result)) { + + xmlwriter_start_element($xw, 'YEAST'); + + field($xw, 'VERSION', '1'); + field($xw, 'NAME', $row['name']); + field($xw, 'TYPE', $yeasttype[$row['type']]); + field($xw, 'FORM', $yeastform[$row['form']]); + field($xw, 'AMOUNT_IS_WEIGHT', ($row['form'] == '1' || $row['form'] == '6') ? 'TRUE':'FALSE'); + field($xw, 'LABORATORY', $row['laboratory']); + if (strlen($row['product_id'])) + field($xw, 'PRODUCT_ID', $row['product_id']); + field($xw, 'MIN_TEMPERATURE', sprintf("%.4f",floatval($row['min_temperature']))); + field($xw, 'MAX_TEMPERATURE', sprintf("%.4f",floatval($row['max_temperature']))); + field($xw, 'ATTENUATION', sprintf("%.4f",floatval($row['attenuation']))); + field($xw, 'ADD_TO_SECONDARY', ($row['use'] == 0) ? 'FALSE':'TRUE'); + field($xw, 'FLOCCULATION', $yeastflocculation[$row['flocculation']]); + field($xw, 'MAX_REUSE', $row['max_reuse']); + if (floatval($row['cost']) > 0) + field($xw, 'COST', sprintf("%.5f",floatval($row['cost']))); + if (strlen($row['notes'])) + field($xw, 'NOTES', $row['notes']); + + xmlwriter_end_element($xw); // YEAST +} +xmlwriter_end_element($xw); // YEASTS + +$beerxml = xmlwriter_output_memory($xw); + +Header('Content-type: text/xml'); +header('Content-Disposition: attachment; filename="yeasts.xml"'); +header('Content-Transfer-Encoding: binary'); +header('Expires: 0'); +header('Pragma: no-cache'); +header('Content-Length: '.strlen($beerxml)); +exit($beerxml);