|
1 <?php |
|
2 require_once('config.php'); |
|
3 require("version.php"); |
|
4 require("includes/formulas.php"); |
|
5 |
|
6 |
|
7 $target_dir = "tmp/"; |
|
8 $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); |
|
9 $uploadOk = 1; |
|
10 $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); |
|
11 |
|
12 // Check if file already exists |
|
13 if (file_exists($target_file)) { |
|
14 echo "Fout 1: bestand bestaat al. "; |
|
15 $uploadOk = 0; |
|
16 } |
|
17 // Check file size |
|
18 if ($_FILES["fileToUpload"]["size"] > 500000 && $uploadOk) { |
|
19 echo "Fout 2: het bestand is te groot. "; |
|
20 $uploadOk = 0; |
|
21 } |
|
22 // Allow certain file formats |
|
23 if ($imageFileType != "xml" && $uploadOk) { |
|
24 echo "Fout 3: alleen XML bestanden toegestaan. "; |
|
25 $uploadOk = 0; |
|
26 } |
|
27 // Check if $uploadOk is set to 0 by an error |
|
28 if ($uploadOk == 0) { |
|
29 exit; |
|
30 } |
|
31 |
|
32 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { |
|
33 echo "Verwerken bestand ". basename( $_FILES["fileToUpload"]["name"]). "<br />"; |
|
34 } else { |
|
35 echo "Fout 4: er ging iets fout met de upload."; |
|
36 exit; |
|
37 } |
|
38 |
|
39 |
|
40 $db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); |
|
41 if (! $db) { |
|
42 echo "Fout 5: ".mysqli_connect_errno()." ".mysqli_connect_error(); |
|
43 exit; |
|
44 } |
|
45 mysqli_set_charset($db, "utf8" ); |
|
46 date_default_timezone_set('Europe/Amsterdam'); |
|
47 |
|
48 |
|
49 $imported = 0; |
|
50 $myfermentables= simplexml_load_file($target_file); |
|
51 |
|
52 |
|
53 foreach ($myfermentables->FERMENTABLE as $fermentable) { |
|
54 |
|
55 $sql = "INSERT INTO inventory_fermentables SET name='" . mysqli_real_escape_string($db, $fermentable->NAME); |
|
56 if ($fermentable->TYPE == 'Grain') |
|
57 $sql .= "', type='0"; |
|
58 else if ($fermentable->TYPE == 'Sugar') |
|
59 $sql .= "', type='1"; |
|
60 else if ($fermentable->TYPE == 'Extract') |
|
61 $sql .= "', type='2"; |
|
62 else if ($fermentable->TYPE == 'Dry extract') |
|
63 $sql .= "', type='3"; |
|
64 else if ($fermentable->TYPE == 'Adjunct') |
|
65 $sql .= "', type='4"; |
|
66 else |
|
67 echo "Unknown TYPE " . $fermentable->TYPE . "<br />"; |
|
68 if ($fermentable->YIELD) |
|
69 $sql .= "', yield='" . floatval($fermentable->YIELD); |
|
70 if ($fermentable->COLOR) { |
|
71 $sql .= "', color='" . srm_to_ebc(floatval($fermentable->COLOR)); |
|
72 } |
|
73 ($fermentable->ADD_AFTER_BOIL == "TRUE") ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; |
|
74 if ($fermentable->ADDED == 'Mash') |
|
75 $sql .= "', added='0"; |
|
76 else if ($fermentable->ADDED == 'Boil') |
|
77 $sql .= "', added='1"; |
|
78 else if ($fermentable->ADDED == 'Fermentation') |
|
79 $sql .= "', added='2"; |
|
80 else if ($fermentable->ADDED == 'Lagering') |
|
81 $sql .= "', added='3"; |
|
82 else if ($fermentable->ADDED == 'Bottle') |
|
83 $sql .= "', added='4"; |
|
84 else |
|
85 echo "Unknown ADDED " . $fermentable->ADDED . "<br />"; |
|
86 |
|
87 $sql .= "', origin='" . mysqli_real_escape_string($db, $fermentable->ORIGIN); |
|
88 $sql .= "', supplier='" . mysqli_real_escape_string($db, $fermentable->SUPPLIER); |
|
89 $sql .= "', notes='" . mysqli_real_escape_string($db, $fermentable->NOTES); |
|
90 if ($fermentable->COARSE_FINE_DIFF) |
|
91 $sql .= "', coarse_fine_diff='" . floatval($fermentable->COARSE_FINE_DIFF); |
|
92 if ($fermentable->MOISTURE) |
|
93 $sql .= "', moisture='" . floatval($fermentable->MOISTURE); |
|
94 if ($fermentable->DIASTATIC_POWER) |
|
95 $sql .= "', diastatic_power='" . floatval($fermentable->DIASTATIC_POWER); |
|
96 if ($fermentable->PROTEIN) |
|
97 $sql .= "', protein='" . floatval($fermentable->PROTEIN); |
|
98 if ($fermentable->DISSOLVED_PROTEIN) |
|
99 $sql .= "', dissolved_protein='" . floatval($fermentable->DISSOLVED_PROTEIN); |
|
100 if ($fermentable->MAX_IN_BATCH) |
|
101 $sql .= "', max_in_batch='" . floatval($fermentable->MAX_IN_BATCH); |
|
102 ($fermentable->RECOMMEND_MASH == "TRUE") ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; |
|
103 ($fermentable->ALWAYS_ON_STOCK == "TRUE") ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
|
104 if ($fermentable->INVENTORY) |
|
105 $sql .= "', inventory='" . floatval($fermentable->INVENTORY); |
|
106 if ($fermentable->COST) |
|
107 $sql .= "', cost='" . floatval($fermentable->COST); |
|
108 |
|
109 /* |
|
110 * These are not beerxml standard: |
|
111 */ |
|
112 if ($fermentable->DI_pH) |
|
113 $sql .= "', di_ph='" . floatval($fermentable->DI_pH); |
|
114 if ($fermentable->{'ACID_TO_pH_5.7'}) |
|
115 $sql .= "', acid_to_ph_57='" . floatval($fermentable->{'ACID_TO_pH_5.7'}); |
|
116 if ($fermentable->GRAINTYPE == 'Base') |
|
117 $sql .= "', graintype='0"; |
|
118 else if ($fermentable->GRAINTYPE == 'Roast') |
|
119 $sql .= "', graintype='1"; |
|
120 else if ($fermentable->GRAINTYPE == 'Crystal') |
|
121 $sql .= "', graintype='2"; |
|
122 else if ($fermentable->GRAINTYPE == 'Kilned') |
|
123 $sql .= "', graintype='3"; |
|
124 else if ($fermentable->GRAINTYPE == 'Sour malt') |
|
125 $sql .= "', graintype='4"; |
|
126 else if ($fermentable->GRAINTYPE == 'Special') |
|
127 $sql .= "', graintype='5"; |
|
128 else if ($fermentable->GRAINTYPE == 'No malt') |
|
129 $sql .= "', graintype='6"; |
|
130 else |
|
131 echo "Unknown GRAINTYPE " . $fermentable->GRAINTYPE . "<br />"; |
|
132 $sql .= "';"; |
|
133 if (! $result = mysqli_query($db, $sql)) { |
|
134 echo "Fout 8: " . mysqli_error($db) . "<br />"; |
|
135 } else { |
|
136 echo "+ " . $fermentable->NAME . "<br />"; |
|
137 $imported++; |
|
138 } |
|
139 } |
|
140 |
|
141 if ($imported == 0) { |
|
142 echo "Fout 7: geen vergistbare ingredienten in dit bestand.<br />"; |
|
143 } else { |
|
144 echo $imported . " ingredienten toegevoegd.<br />"; |
|
145 } |
|
146 |
|
147 |
|
148 |
|
149 // Don't clutter the upload directory. |
|
150 unlink($target_file); |
|
151 |
|
152 ?> |