www/export_yeasts.php

Wed, 06 May 2020 14:14:14 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 06 May 2020 14:14:14 +0200
changeset 667
1246550451ca
parent 608
0a8495edf53c
child 788
812ce4c5da2a
permissions
-rw-r--r--

Removed the last compressed css file. Reworked all mash steps, implemented deconction steps. Added calculations for infuse amounts and decoctions amounts. The mash steps are now manually sorted in the editor grids to have full control over the steps order. Display errors in red in the grid. Updated beerxml export, the product checklist and print output of the products and recipes for all these mash steps changes.

<?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);

mercurial