|
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_miscs ORDER BY name"); |
|
16 $row = mysqli_fetch_array($result); |
|
17 |
|
18 |
|
19 $misctype = array( 'Spice', 'Herb', 'Flavor', 'Fining', 'Water agent', 'Yeast nutrient', 'Other' ); |
|
20 $miscuse = array( 'Starter', 'Mash', 'Boil', 'Primary', 'Secondary', 'Bottling' ); |
|
21 |
|
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, 'MISCS'); |
|
35 while ($row = mysqli_fetch_array($result)) { |
|
36 |
|
37 xmlwriter_start_element($xw, 'MISC'); |
|
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, $misctype[$row['type']]); |
|
49 xmlwriter_end_element($xw); |
|
50 |
|
51 xmlwriter_start_element($xw, 'AMOUNT_IS_WEIGHT'); |
|
52 ($row['amount_is_weight']) ? xmlwriter_text($xw, 'TRUE') : xmlwriter_text($xw, 'FALSE'); |
|
53 xmlwriter_end_element($xw); |
|
54 |
|
55 xmlwriter_start_element($xw, 'USE'); |
|
56 xmlwriter_text($xw, $miscuse[$row['use_use']]); |
|
57 xmlwriter_end_element($xw); |
|
58 |
|
59 if (floatval($row['time']) > 0) { |
|
60 xmlwriter_start_element($xw, 'TIME'); |
|
61 xmlwriter_text($xw, sprintf("%.3f",floatval($row['time']))); |
|
62 xmlwriter_end_element($xw); |
|
63 } |
|
64 |
|
65 if (floatval($row['cost']) > 0) { |
|
66 xmlwriter_start_element($xw, 'COST'); |
|
67 xmlwriter_text($xw, sprintf("%.5f",floatval($row['cost']))); |
|
68 xmlwriter_end_element($xw); |
|
69 } |
|
70 |
|
71 xmlwriter_start_element($xw, 'ALWAYS_ON_STOCK'); |
|
72 ($row['always_on_stock']) ? xmlwriter_text($xw, 'TRUE') : xmlwriter_text($xw, 'FALSE'); |
|
73 xmlwriter_end_element($xw); |
|
74 |
|
75 if (strlen($row['notes'])) { |
|
76 xmlwriter_start_element($xw, 'NOTES'); |
|
77 xmlwriter_text($xw, $row['notes']); |
|
78 xmlwriter_end_element($xw); |
|
79 } |
|
80 |
|
81 if (strlen($row['use_for'])) { |
|
82 xmlwriter_start_element($xw, 'USE_FOR'); |
|
83 xmlwriter_text($xw, $row['use_for']); |
|
84 xmlwriter_end_element($xw); |
|
85 } |
|
86 |
|
87 xmlwriter_end_element($xw); // MISC |
|
88 } |
|
89 xmlwriter_end_element($xw); // MISCS |
|
90 |
|
91 $beerxml = xmlwriter_output_memory($xw); |
|
92 |
|
93 Header('Content-type: text/xml'); |
|
94 header('Content-Disposition: attachment; filename="miscs.xml"'); |
|
95 header('Content-Transfer-Encoding: binary'); |
|
96 header('Expires: 0'); |
|
97 header('Pragma: no-cache'); |
|
98 header('Content-Length: '.strlen($beerxml)); |
|
99 exit($beerxml); |