|
1 <?php |
|
2 require_once($_SERVER['DOCUMENT_ROOT'].'/config.php'); |
|
3 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/formulas.php'); |
|
4 |
|
5 |
|
6 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); |
|
7 if (! $link) { |
|
8 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
|
9 } |
|
10 if (! mysqli_set_charset($link, "utf8" )) { |
|
11 echo "error"; |
|
12 return 1; |
|
13 } |
|
14 |
|
15 $result = mysqli_query($link, "SELECT * FROM inventory_yeasts ORDER BY laboratory,product_id,name"); |
|
16 $row = mysqli_fetch_array($result); |
|
17 |
|
18 |
|
19 $yeasttype = array( 'Lager', 'Ale', 'Wheat', 'Wine', 'Champagne', 'Other', 'Other', 'Other', 'Other', 'Other' ); |
|
20 $yeastform = array( 'Liquid', 'Dry', 'Slant', 'Culture', 'Frozen', 'Bottle', 'Dry' ); |
|
21 $yeastflocculation = array( 'Low', 'Medium', 'High', 'Very high' ); |
|
22 |
|
23 |
|
24 /* |
|
25 * Create beerxml output |
|
26 */ |
|
27 $xw = xmlwriter_open_memory(); |
|
28 xmlwriter_set_indent($xw, 1); |
|
29 $res = xmlwriter_set_indent_string($xw, ' '); |
|
30 |
|
31 xmlwriter_start_document($xw, '1.0', 'UTF-8'); |
|
32 |
|
33 |
|
34 xmlwriter_start_element($xw, 'YEASTS'); |
|
35 while ($row = mysqli_fetch_array($result)) { |
|
36 |
|
37 xmlwriter_start_element($xw, 'YEAST'); |
|
38 |
|
39 xmlwriter_start_element($xw, 'VERSION'); |
|
40 xmlwriter_text($xw, '1'); |
|
41 xmlwriter_end_element($xw); |
|
42 |
|
43 xmlwriter_start_element($xw, 'NAME'); |
|
44 xmlwriter_text($xw, $row['name']); |
|
45 xmlwriter_end_element($xw); |
|
46 |
|
47 xmlwriter_start_element($xw, 'TYPE'); |
|
48 xmlwriter_text($xw, $yeasttype[$row['type']]); |
|
49 xmlwriter_end_element($xw); |
|
50 |
|
51 xmlwriter_start_element($xw, 'FORM'); |
|
52 xmlwriter_text($xw, $yeastform[$row['form']]); |
|
53 xmlwriter_end_element($xw); |
|
54 |
|
55 xmlwriter_start_element($xw, 'AMOUNT_IS_WEIGHT'); |
|
56 ($row['amount_is_weight']) ? xmlwriter_text($xw, 'TRUE') : xmlwriter_text($xw, 'FALSE'); |
|
57 xmlwriter_end_element($xw); |
|
58 |
|
59 xmlwriter_start_element($xw, 'LABORATORY'); |
|
60 xmlwriter_text($xw, $row['laboratory']); |
|
61 xmlwriter_end_element($xw); |
|
62 |
|
63 if (strlen($row['product_id'])) { |
|
64 xmlwriter_start_element($xw, 'PRODUCT_ID'); |
|
65 xmlwriter_text($xw, $row['product_id']); |
|
66 xmlwriter_end_element($xw); |
|
67 } |
|
68 |
|
69 xmlwriter_start_element($xw, 'MIN_TEMPERATURE'); |
|
70 xmlwriter_text($xw, sprintf("%.4f",floatval($row['min_temperature']))); |
|
71 xmlwriter_end_element($xw); |
|
72 |
|
73 xmlwriter_start_element($xw, 'MAX_TEMPERATURE'); |
|
74 xmlwriter_text($xw, sprintf("%.4f",floatval($row['max_temperature']))); |
|
75 xmlwriter_end_element($xw); |
|
76 |
|
77 xmlwriter_start_element($xw, 'ATTENUATION'); |
|
78 xmlwriter_text($xw, sprintf("%.4f",floatval($row['attenuation']))); |
|
79 xmlwriter_end_element($xw); |
|
80 |
|
81 xmlwriter_start_element($xw, 'ADD_TO_SECONDARY'); |
|
82 ($row['use'] == 0) ? xmlwriter_text($xw, 'FALSE') : xmlwriter_text($xw, 'TRUE'); |
|
83 xmlwriter_end_element($xw); |
|
84 |
|
85 xmlwriter_start_element($xw, 'FLOCCULATION'); |
|
86 xmlwriter_text($xw, $yeastflocculation[$row['flocculation']]); |
|
87 xmlwriter_end_element($xw); |
|
88 |
|
89 xmlwriter_start_element($xw, 'MAX_REUSE'); |
|
90 xmlwriter_text($xw, $row['max_reuse']); |
|
91 xmlwriter_end_element($xw); |
|
92 |
|
93 if (floatval($row['cost']) > 0) { |
|
94 xmlwriter_start_element($xw, 'COST'); |
|
95 xmlwriter_text($xw, sprintf("%.5f",floatval($row['cost']))); |
|
96 xmlwriter_end_element($xw); |
|
97 } |
|
98 |
|
99 if (strlen($row['notes'])) { |
|
100 xmlwriter_start_element($xw, 'NOTES'); |
|
101 xmlwriter_text($xw, $row['notes']); |
|
102 xmlwriter_end_element($xw); |
|
103 } |
|
104 |
|
105 |
|
106 xmlwriter_end_element($xw); // MISC |
|
107 } |
|
108 xmlwriter_end_element($xw); // MISCS |
|
109 |
|
110 $beerxml = xmlwriter_output_memory($xw); |
|
111 |
|
112 Header('Content-type: text/xml'); |
|
113 header('Content-Disposition: attachment; filename="yeasts.xml"'); |
|
114 header('Content-Transfer-Encoding: binary'); |
|
115 header('Expires: 0'); |
|
116 header('Pragma: no-cache'); |
|
117 header('Content-Length: '.strlen($beerxml)); |
|
118 exit($beerxml); |