www/export_yeasts.php

Fri, 17 Jun 2022 16:18:04 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 17 Jun 2022 16:18:04 +0200
changeset 790
98bd22f6629b
parent 788
812ce4c5da2a
permissions
-rw-r--r--

Version 0.3.39. Log ispindel, fermenters and co2pressure in MySQL. Limit logging to at most once per 10 minutes.

563
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/formulas.php');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 if (! $link) {
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 }
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 if (! mysqli_set_charset($link, "utf8" )) {
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 echo "error";
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 return 1;
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 }
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 $result = mysqli_query($link, "SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name");
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
608
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
17 function field($x, $field, $value) {
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
18 xmlwriter_start_element($x, $field);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
19 xmlwriter_text($x, $value);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
20 xmlwriter_end_element($x);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
21 }
563
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 $yeasttype = array( 'Lager', 'Ale', 'Wheat', 'Wine', 'Champagne', 'Other', 'Other', 'Other', 'Other', 'Other' );
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 $yeastform = array( 'Liquid', 'Dry', 'Slant', 'Culture', 'Frozen', 'Bottle', 'Dry' );
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 $yeastflocculation = array( 'Low', 'Medium', 'High', 'Very high' );
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 /*
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 * Create beerxml output
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 */
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 $xw = xmlwriter_open_memory();
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 xmlwriter_set_indent($xw, 1);
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 $res = xmlwriter_set_indent_string($xw, ' ');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 xmlwriter_start_document($xw, '1.0', 'UTF-8');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 xmlwriter_start_element($xw, 'YEASTS');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 while ($row = mysqli_fetch_array($result)) {
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 xmlwriter_start_element($xw, 'YEAST');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
608
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
43 field($xw, 'VERSION', '1');
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
44 field($xw, 'NAME', $row['name']);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
45 field($xw, 'TYPE', $yeasttype[$row['type']]);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
46 field($xw, 'FORM', $yeastform[$row['form']]);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
47 field($xw, 'AMOUNT_IS_WEIGHT', ($row['form'] == '1' || $row['form'] == '6') ? 'TRUE':'FALSE');
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
48 field($xw, 'LABORATORY', $row['laboratory']);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
49 if (strlen($row['product_id']))
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
50 field($xw, 'PRODUCT_ID', $row['product_id']);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
51 field($xw, 'MIN_TEMPERATURE', sprintf("%.4f",floatval($row['min_temperature'])));
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
52 field($xw, 'MAX_TEMPERATURE', sprintf("%.4f",floatval($row['max_temperature'])));
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
53 field($xw, 'ATTENUATION', sprintf("%.4f",floatval($row['attenuation'])));
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
54 field($xw, 'ADD_TO_SECONDARY', ($row['use'] == 0) ? 'FALSE':'TRUE');
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
55 field($xw, 'FLOCCULATION', $yeastflocculation[$row['flocculation']]);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
56 field($xw, 'MAX_REUSE', $row['max_reuse']);
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
57 if (floatval($row['cost']) > 0)
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
58 field($xw, 'COST', sprintf("%.5f",floatval($row['cost'])));
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
59 if (strlen($row['notes']))
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
60 field($xw, 'NOTES', $row['notes']);
563
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61
608
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
62 xmlwriter_end_element($xw); // YEAST
563
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 }
608
0a8495edf53c Fixed wrong AMOUNT_IS_WEIGHT values in yeasts export.
Michiel Broek <mbroek@mbse.eu>
parents: 563
diff changeset
64 xmlwriter_end_element($xw); // YEASTS
563
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 $beerxml = xmlwriter_output_memory($xw);
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 Header('Content-type: text/xml');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 header('Content-Disposition: attachment; filename="yeasts.xml"');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 header('Content-Transfer-Encoding: binary');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 header('Expires: 0');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 header('Pragma: no-cache');
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 header('Content-Length: '.strlen($beerxml));
acdd54144838 Added export inventory and profiles in beerxml format. Small fixes in beerxml recipe and product export.
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 exit($beerxml);

mercurial