Wed, 29 Aug 2018 14:44:12 +0200
Renamed monitor database tables
11 | 1 | <?php |
2 | /* | |
3 | * Import inventory from brouwhulp | |
4 | */ | |
5 | ||
6 | require("../config.php"); | |
7 | require("../version.php"); | |
8 | require("../includes/formulas.php"); | |
9 | ||
10 | echo "Start adding data from brouwhulp\n"; | |
11 | ||
12 | $db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
13 | if (! $db) { | |
14 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
15 | } | |
16 | ||
17 | $brouwhulp = '/home/mbroek/Documents/brouwhulp'; | |
18 | ||
19 | ||
20 | function do_fermentables() | |
21 | { | |
22 | global $brouwhulp, $db; | |
23 | ||
24 | echo " Start adding fermentables to the database\n"; | |
25 | $sql = "TRUNCATE TABLE inventory_fermentables;"; | |
26 | if (! $result = mysqli_query($db, $sql)) { | |
27 | printf("Error: %s\n", mysqli_error($db)); | |
28 | } | |
29 | $myfermentables = simplexml_load_file($brouwhulp . '/fermentables.xml'); | |
30 | ||
31 | foreach ($myfermentables->FERMENTABLE as $fermentable) { | |
32 | ||
33 | $sql = "INSERT INTO inventory_fermentables SET name='" . mysqli_real_escape_string($db, $fermentable->NAME); | |
34 | $sql .= "', type='" . $fermentable->TYPE; | |
35 | if ($fermentable->YIELD) | |
36 | $sql .= "', yield='" . $fermentable->YIELD; | |
37 | if ($fermentable->COLOR) { | |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
38 | $srm = floatval($fermentable->COLOR); |
11 | 39 | $ebc = srm_to_ebc($srm); |
40 | $sql .= "', color='" . $ebc; | |
41 | } | |
42 | ($fermentable->ADD_AFTER_BOIL == "TRUE") ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; | |
43 | $sql .= "', origin='" . mysqli_real_escape_string($db, $fermentable->ORIGIN); | |
44 | $sql .= "', supplier='" . mysqli_real_escape_string($db, $fermentable->SUPPLIER); | |
45 | $sql .= "', notes='" . mysqli_real_escape_string($db, $fermentable->NOTES); | |
46 | if ($fermentable->COARSE_FINE_DIFF) | |
47 | $sql .= "', coarse_fine_diff='" . $fermentable->COARSE_FINE_DIFF; | |
48 | if ($fermentable->MOISTURE) | |
49 | $sql .= "', moisture='" . $fermentable->MOISTURE; | |
50 | if ($fermentable->DIASTATIC_POWER) | |
51 | $sql .= "', diastatic_power='" . $fermentable->DIASTATIC_POWER; | |
52 | if ($fermentable->PROTEIN) | |
53 | $sql .= "', protein='" . $fermentable->PROTEIN; | |
54 | if ($fermentable->MAX_IN_BATCH) | |
55 | $sql .= "', max_in_batch='" . $fermentable->MAX_IN_BATCH; | |
21
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
56 | ($fermentable->RECOMMEND_MASH == "TRUE") ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; |
11 | 57 | if ($fermentable->IBU_GAL_PER_LB) |
58 | $sql .= "', ibu_gal_per_lb='" . $fermentable->IBU_GAL_PER_LB; | |
21
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
59 | ($fermentable->ALWAYS_ON_STOCK == "TRUE") ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
11 | 60 | if ($fermentable->INVENTORY) |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
61 | $sql .= "', inventory='" . floatval($fermentable->INVENTORY); |
11 | 62 | if ($fermentable->COST) |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
63 | $sql .= "', cost='" . floatval($fermentable->COST); |
11 | 64 | /* |
65 | * These are not beerxml standard: | |
66 | */ | |
67 | if ($fermentable->DI_pH) | |
68 | $sql .= "', di_ph='" . $fermentable->DI_pH; | |
69 | if ($fermentable->{'ACID_TO_pH_5.7'}) | |
70 | $sql .= "', acid_to_ph_57='" . $fermentable->{'ACID_TO_pH_5.7'}; | |
71 | $sql .= "', graintype='" . $fermentable->GRAINTYPE; | |
72 | $sql .= "';"; | |
73 | if (! $result = mysqli_query($db, $sql)) { | |
74 | printf("Error: %s\n", mysqli_error($db)); | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | ||
80 | function do_hops() | |
81 | { | |
82 | global $brouwhulp, $db; | |
83 | ||
84 | echo " Start adding hops to the database\n"; | |
85 | $sql = "TRUNCATE TABLE inventory_hops;"; | |
86 | if (! $result = mysqli_query($db, $sql)) { | |
87 | printf("Error: %s\n", mysqli_error($db)); | |
88 | } | |
89 | ||
90 | $myhops = simplexml_load_file($brouwhulp . '/hops.xml'); | |
91 | ||
92 | foreach ($myhops->HOP as $hop) { | |
93 | ||
94 | $sql = "INSERT INTO inventory_hops SET name='" . mysqli_real_escape_string($db, $hop->NAME); | |
95 | if ($hop->ALPHA) | |
96 | $sql .= "', alpha='" . $hop->ALPHA; | |
97 | if ($hop->BETA) | |
98 | $sql .= "', beta='" . $hop->BETA; | |
99 | if ($hop->HUMULENE) | |
100 | $sql .= "', humulene='" . $hop->HUMULENE; | |
101 | if ($hop->CARYOPHYLLENE) | |
102 | $sql .= "', caryophyllene='" . $hop->CARYOPHYLLENE; | |
103 | if ($hop->COHUMULONE) | |
104 | $sql .= "', cohumulone='" . $hop->COHUMULONE; | |
105 | if ($hop->MYCRENE) | |
106 | $sql .= "', myrcene='" . $hop->MYCRENE; | |
107 | if ($hop->HSI) | |
108 | $sql .= "', hsi='" . $hop->HSI; | |
109 | $sql .= "', useat='" . $hop->USE; | |
110 | $sql .= "', type='" . $hop->TYPE; | |
111 | $sql .= "', form='" . $hop->FORM; | |
112 | $sql .= "', notes='" . mysqli_real_escape_string($db, $hop->NOTES); | |
113 | $sql .= "', origin='" . mysqli_real_escape_string($db, $hop->ORIGIN); | |
114 | $sql .= "', substitutes='" . mysqli_real_escape_string($db, $hop->SUBSTITUTES); | |
21
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
115 | ($hop->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
11 | 116 | if ($hop->INVENTORY) |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
117 | $sql .= "', inventory='" . floatval($hop->INVENTORY) / 1000.0; |
11 | 118 | if ($hop->COST) |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
119 | $sql .= "', cost='" . floatval($hop->COST); |
13 | 120 | if ($hop->TOTAL_OIL) |
121 | $sql .= "', total_oil='" . $hop->TOTAL_OIL; | |
11 | 122 | $sql .= "';"; |
123 | if (! $result = mysqli_query($db, $sql)) { | |
124 | printf("Error: %s\n", mysqli_error($db)); | |
125 | } | |
126 | } | |
127 | ||
128 | } | |
129 | ||
130 | ||
131 | ||
132 | function do_yeasts() | |
133 | { | |
134 | global $brouwhulp, $db; | |
135 | ||
136 | echo " Start adding yeasts to the database\n"; | |
137 | $sql = "TRUNCATE TABLE inventory_yeasts;"; | |
138 | if (! $result = mysqli_query($db, $sql)) { | |
139 | printf("Error: %s\n", mysqli_error($db)); | |
140 | } | |
141 | ||
142 | $yeasts = simplexml_load_file($brouwhulp . '/yeasts.xml'); | |
143 | ||
144 | foreach ($yeasts->YEAST as $yeast) { | |
145 | ||
146 | $sql = "INSERT INTO inventory_yeasts SET name='" . mysqli_real_escape_string($db, $yeast->NAME); | |
147 | $sql .= "', type='" . $yeast->TYPE; | |
148 | $sql .= "', form='" . $yeast->FORM; | |
149 | $sql .= "', laboratory='" . mysqli_real_escape_string($db, $yeast->LABORATORY); | |
150 | $sql .= "', product_id='" . mysqli_real_escape_string($db, $yeast->PRODUCT_ID); | |
151 | if ($yeast->MIN_TEMPERATURE) | |
152 | $sql .= "', min_temperature='" . $yeast->MIN_TEMPERATURE; | |
153 | if ($yeast->MAX_TEMPERATURE) | |
154 | $sql .= "', max_temperature='" . $yeast->MAX_TEMPERATURE; | |
155 | $sql .= "', flocculation='" . $yeast->FLOCCULATION; | |
156 | if ($yeast->ATTENUATION) | |
157 | $sql .= "', attenuation='" . $yeast->ATTENUATION; | |
158 | $sql .= "', notes='" . mysqli_real_escape_string($db, $yeast->NOTES); | |
159 | $sql .= "', best_for='" . mysqli_real_escape_string($db, $yeast->BEST_FOR); | |
160 | if ($yeast->MAX_REUSE) | |
161 | $sql .= "', max_reuse='" . $yeast->MAX_REUSE; | |
162 | if ($yeast->INVENTORY) | |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
163 | $sql .= "', inventory='" . floatval($yeast->INVENTORY) / 1000.0; |
11 | 164 | if ($yeast->COST) |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
165 | $sql .= "', cost='" . floatval($yeast->COST) * 1000.0; |
11 | 166 | if ($yeast->CULTURE_DATE) { |
167 | $date = substr($yeast->CULTURE_DATE, 6, 4) . '-' . substr($yeast->CULTURE_DATE, 3, 2) . '-' . substr($yeast->CULTURE_DATE, 0, 2); | |
168 | $sql .= "', production_date='" . $date; | |
169 | } | |
170 | $sql .= "';"; | |
171 | if (! $result = mysqli_query($db, $sql)) { | |
172 | printf("Error: %s\n", mysqli_error($db)); | |
173 | } | |
174 | } | |
175 | } | |
176 | ||
177 | ||
178 | ||
179 | function do_waters() | |
180 | { | |
181 | global $brouwhulp, $db; | |
182 | ||
183 | echo " Start adding waters to the database\n"; | |
184 | $sql = "TRUNCATE TABLE inventory_water_profiles;"; | |
185 | if (! $result = mysqli_query($db, $sql)) { | |
186 | printf("Error: %s\n", mysqli_error($db)); | |
187 | } | |
15 | 188 | $sql = "TRUNCATE TABLE inventory_water_sources;"; |
189 | if (! $result = mysqli_query($db, $sql)) { | |
190 | printf("Error: %s\n", mysqli_error($db)); | |
191 | } | |
11 | 192 | |
193 | $waters = simplexml_load_file($brouwhulp . '/waters.xml'); | |
194 | ||
195 | foreach ($waters->WATER as $water) { | |
196 | ||
15 | 197 | if (($water->NAME == "Gedemineraliseerd water") || ($water->NAME == "Cristalline") || ($water->NAME == "Montille (Delhaize)") || |
198 | ($water->NAME == "Spa Reine") || ($water->NAME == "Velsen") || ($water->NAME == "Zutphen") || | |
199 | ($water->NAME == "Aurele Bronwater (Colruyt)")) { | |
21
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
200 | $sql = "INSERT INTO inventory_water_sources SET name='" . mysqli_real_escape_string($db, $water->NAME); |
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
201 | ($water->DEFAULT_WATER == 'TRUE') ? $sql .= "', default_water='1" : $sql .= "', default_water='0"; |
22
99c02fa797f9
Added inventory water profiles
Michiel Broek <mbroek@mbse.eu>
parents:
21
diff
changeset
|
202 | ($water->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
15 | 203 | } else { |
204 | $sql = "INSERT INTO inventory_water_profiles SET name='" . mysqli_real_escape_string($db, $water->NAME); | |
205 | } | |
206 | ||
11 | 207 | if ($water->NOTES) |
208 | $sql .= "', notes='" . mysqli_real_escape_string($db, $water->NOTES); | |
209 | $sql .= "', calcium='" . $water->CALCIUM; | |
210 | $sql .= "', bicarbonate='" . $water->BICARBONATE; | |
211 | $sql .= "', sulfate='" . $water->SULFATE; | |
212 | $sql .= "', chloride='" . $water->CHLORIDE; | |
213 | $sql .= "', sodium='" . $water->SODIUM; | |
214 | $sql .= "', magnesium='" . $water->MAGNESIUM; | |
215 | $sql .= "', ph='" . $water->PH; | |
216 | if ($water->TOTAL_ALKALINITY) | |
217 | $sql .= "', total_alkalinity='" . $water->TOTAL_ALKALINITY; | |
218 | $sql .= "';"; | |
219 | if (! $result = mysqli_query($db, $sql)) { | |
220 | printf("Error: %s\n", mysqli_error($db)); | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | ||
226 | ||
227 | function do_miscs() | |
228 | { | |
229 | global $brouwhulp, $db; | |
230 | ||
231 | echo " Start adding miscs to the database\n"; | |
232 | $sql = "TRUNCATE TABLE inventory_miscs;"; | |
233 | if (! $result = mysqli_query($db, $sql)) { | |
234 | printf("Error: %s\n", mysqli_error($db)); | |
235 | } | |
236 | ||
237 | $miscs = simplexml_load_file($brouwhulp . '/miscs.xml'); | |
238 | ||
239 | foreach ($miscs->MISC as $misc) { | |
240 | ||
241 | $sql = "INSERT INTO inventory_miscs SET name='" . mysqli_real_escape_string($db, $misc->NAME); | |
242 | if ($misc->NOTES) | |
243 | $sql .= "', notes='" . mysqli_real_escape_string($db, $misc->NOTES); | |
244 | $sql .= "', type='" . $misc->TYPE; | |
245 | $sql .= "', use_use='" . $misc->USE; | |
246 | $sql .= "', time='" . $misc->TIME; | |
21
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
247 | ($misc->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='1" : $sql .= "', amount_is_weight='0"; |
11 | 248 | if ($misc->USE_FOR) |
249 | $sql .= "', use_for='" . mysqli_real_escape_string($db, $misc->USE_FOR); | |
250 | if ($misc->ALWAYS_ON_STOCK) | |
21
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
251 | ($misc->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
11 | 252 | if ($misc->INVENTORY) |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
253 | $sql .= "', inventory='" . floatval($misc->INVENTORY) / 1000.0; |
11 | 254 | if ($misc->COST) |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
255 | $sql .= "', cost='" . floatval($misc->COST); |
11 | 256 | $sql .= "';"; |
257 | if (! $result = mysqli_query($db, $sql)) { | |
258 | printf("Error: %s\n", mysqli_error($db)); | |
259 | } | |
260 | } | |
261 | } | |
262 | ||
263 | ||
264 | ||
265 | function do_equipments() | |
266 | { | |
267 | global $brouwhulp, $db; | |
268 | ||
269 | echo " Start adding equipments to the database\n"; | |
270 | $sql = "TRUNCATE TABLE inventory_equipments;"; | |
271 | if (! $result = mysqli_query($db, $sql)) { | |
272 | printf("Error: %s\n", mysqli_error($db)); | |
273 | } | |
274 | ||
275 | $equipments = simplexml_load_file($brouwhulp . '/equipments.xml'); | |
276 | ||
277 | foreach ($equipments->EQUIPMENT as $equipment) { | |
278 | ||
279 | $sql = "INSERT INTO inventory_equipments SET name='" . mysqli_real_escape_string($db, $equipment->NAME); | |
280 | $sql .= "', boil_size='" . $equipment->BOIL_SIZE; | |
281 | $sql .= "', batch_size='" . $equipment->BATCH_SIZE; | |
282 | $sql .= "', tun_volume='" . $equipment->TUN_VOLUME; | |
283 | $sql .= "', tun_weight='" . $equipment->TUN_WEIGHT; | |
284 | $sql .= "', tun_specific_heat='" . $equipment->TUN_SPECIFIC_HEAT; | |
285 | $sql .= "', top_up_water='" . $equipment->TOP_UP_WATER; | |
286 | $sql .= "', trub_chiller_loss='" . $equipment->TRUB_CHILLER_LOSS; | |
287 | /* | |
288 | * Brouwhulp uses a percentage for the evaporation rate. This is wrong | |
289 | * but was made so because the beerxml standard requires this. What we | |
290 | * do is calculate the actual evaporation and store that. | |
291 | * This is what we use. Brouwhulp calculates this on the fly. | |
292 | */ | |
293 | $sql .= "', evap_rate='" . ($equipment->EVAP_RATE * $equipment->BOIL_SIZE) / 100.0; | |
294 | $sql .= "', boil_time='" . $equipment->BOIL_TIME; | |
21
acb2d8098f19
Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
295 | ($equipment->CALC_BOIL_VOLUME == 'TRUE') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0"; |
11 | 296 | $sql .= "', lauter_deadspace='" . $equipment->LAUTER_DEADSPACE; |
297 | $sql .= "', top_up_kettle='" . $equipment->TOP_UP_KETTLE; | |
298 | $sql .= "', hop_utilization='" . $equipment->HOP_UTILIZATION; | |
299 | if ($equipment->NOTES) | |
300 | $sql .= "', notes='" . mysqli_real_escape_string($db, $equipment->NOTES); | |
301 | $sql .= "', lauter_volume='" . $equipment->LAUTER_VOLUME; | |
302 | $sql .= "', kettle_volume='" . $equipment->KETTLE_VOLUME; | |
303 | if ($equipment->TUN_MATERIAL) | |
304 | $sql .= "', tun_material='" . mysqli_real_escape_string($db, $equipment->TUN_MATERIAL); | |
305 | $sql .= "', tun_height='" . $equipment->TUN_HEIGHT; | |
306 | $sql .= "', kettle_height='" . $equipment->KETTLE_HEIGHT; | |
307 | $sql .= "', lauter_height='" . $equipment->LAUTER_HEIGHT; | |
308 | $sql .= "', mash_volume='" . $equipment->MASH_VOLUME; | |
309 | $sql .= "', efficiency='" . $equipment->EFFICIENCY; | |
310 | ||
311 | $sql .= "';"; | |
312 | if (! $result = mysqli_query($db, $sql)) { | |
313 | printf("Error: %s\n", mysqli_error($db)); | |
314 | } | |
315 | } | |
316 | } | |
317 | ||
318 | ||
319 | ||
320 | function do_styles() | |
321 | { | |
322 | global $brouwhulp, $db; | |
323 | ||
324 | echo " Start adding styles to the database\n"; | |
325 | $sql = "TRUNCATE TABLE inventory_styles;"; | |
326 | if (! $result = mysqli_query($db, $sql)) { | |
327 | printf("Error: %s\n", mysqli_error($db)); | |
328 | } | |
329 | ||
330 | $styles = simplexml_load_file($brouwhulp . '/styles.xml'); | |
331 | ||
332 | foreach ($styles->STYLE as $style) { | |
333 | ||
334 | $sql = "INSERT INTO inventory_styles SET name='" . mysqli_real_escape_string($db, $style->NAME); | |
335 | if ($style->NOTES) | |
336 | $sql .= "', notes='" . mysqli_real_escape_string($db, $style->NOTES); | |
337 | if ($style->CATEGORY) | |
338 | $sql .= "', category='" . mysqli_real_escape_string($db, $style->CATEGORY); | |
339 | if ($style->CATEGORY_NUMBER) | |
340 | $sql .= "', category_number='" . $style->CATEGORY_NUMBER; | |
341 | if ($style->STYLE_LETTER) | |
342 | $sql .= "', style_letter='" . mysqli_real_escape_string($db, $style->STYLE_LETTER); | |
343 | if ($style->STYLE_GUIDE) | |
344 | $sql .= "', style_guide='" . mysqli_real_escape_string($db, $style->STYLE_GUIDE); | |
345 | $sql .= "', type='" . $style->TYPE; | |
346 | $sql .= "', og_min='" . $style->OG_MIN; | |
347 | $sql .= "', og_max='" . $style->OG_MAX; | |
348 | $sql .= "', fg_min='" . $style->FG_MIN; | |
349 | $sql .= "', fg_max='" . $style->FG_MAX; | |
350 | $sql .= "', ibu_min='" . $style->IBU_MIN; | |
351 | $sql .= "', ibu_max='" . $style->IBU_MAX; | |
352 | $sql .= "', color_min='" . $style->COLOR_MIN; | |
353 | $sql .= "', color_max='" . $style->COLOR_MAX; | |
354 | $sql .= "', carb_min='" . $style->CARB_MIN; | |
355 | $sql .= "', carb_max='" . $style->CARB_MAX; | |
356 | $sql .= "', abv_min='" . $style->ABV_MIN; | |
357 | $sql .= "', abv_max='" . $style->ABV_MAX; | |
358 | if ($style->PROFILE) | |
359 | $sql .= "', profile='" . mysqli_real_escape_string($db, $style->PROFILE); | |
360 | if ($style->INGREDIENTS) | |
361 | $sql .= "', ingredients='" . mysqli_real_escape_string($db, $style->INGREDIENTS); | |
362 | if ($style->EXAMPLES) | |
363 | $sql .= "', examples='" . mysqli_real_escape_string($db, $style->EXAMPLES); | |
364 | ||
365 | $sql .= "';"; | |
366 | if (! $result = mysqli_query($db, $sql)) { | |
367 | printf("Error: %s\n", mysqli_error($db)); | |
368 | } | |
369 | } | |
370 | } | |
371 | ||
372 | ||
373 | ||
374 | function do_mash() | |
375 | { | |
376 | global $brouwhulp, $db; | |
377 | ||
378 | echo " Start adding mash profiles to the database\n"; | |
379 | $sql = "TRUNCATE TABLE inventory_mash_profiles;"; | |
380 | if (! $result = mysqli_query($db, $sql)) { | |
381 | printf("Error: %s\n", mysqli_error($db)); | |
382 | } | |
383 | ||
384 | $mashes = simplexml_load_file($brouwhulp . '/mashs.xml'); | |
385 | ||
386 | foreach ($mashes->MASH as $mash) { | |
387 | $sql = "INSERT INTO inventory_mash_profiles SET name='" . mysqli_real_escape_string($db, $mash->NAME); | |
388 | if ($mash->NOTES) | |
389 | $sql .= "', notes='" . mysqli_real_escape_string($db, $mash->NOTES); | |
390 | ||
391 | /* | |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
392 | * Put the steps in a json array |
11 | 393 | */ |
394 | if ($mash->MASH_STEPS) { | |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
395 | $steps = "["; |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
396 | $comma = FALSE; |
11 | 397 | foreach ($mash->MASH_STEPS->MASH_STEP as $step) { |
398 | ||
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
399 | if ($comma) |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
400 | $steps .= ','; |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
401 | $comma = TRUE; |
38
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
35
diff
changeset
|
402 | $steps .= '{"step_name":"' . mysqli_real_escape_string($db, $step->NAME) . '"'; |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
403 | if ($step->TYPE) { |
38
b7d44c98d609
Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents:
35
diff
changeset
|
404 | $steps .= ',"step_type":"' . $step->TYPE . '"'; |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
405 | } |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
406 | if ($step->STEP_TEMP) { |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
407 | $steps .= ',"step_temp":"' . $step->STEP_TEMP . '"'; |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
408 | } |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
409 | if ($step->STEP_TIME) { |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
410 | $steps .= ',"step_time":"' . $step->STEP_TIME . '"'; |
11 | 411 | } |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
412 | if ($step->RAMP_TIME) { |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
413 | $steps .= ',"ramp_time":"' . $step->RAMP_TIME . '"'; |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
414 | } |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
415 | if ($step->END_TEMP) { |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
416 | $steps .= ',"end_temp":"' . $step->END_TEMP . '"'; |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
417 | } |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
418 | $steps .= "}"; |
11 | 419 | } |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
420 | $steps .= ']'; |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
421 | $sql .= "', steps='" . $steps; |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
422 | } |
35 | 423 | $sql .= "';"; |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
424 | if (! $result = mysqli_query($db, $sql)) { |
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
425 | printf("Error: %s\n", mysqli_error($db)); |
11 | 426 | } |
427 | } | |
428 | } | |
429 | ||
430 | ||
431 | ||
30
f5ab22446aa5
Inventory fermentables and hops to standard weight format.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
432 | do_fermentables(); |
f5ab22446aa5
Inventory fermentables and hops to standard weight format.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
433 | do_hops(); |
32
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
434 | do_yeasts(); |
8bb369f32ef9
Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
435 | do_miscs(); |
23
4b157d7a1cee
Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
436 | //do_waters(); |
11 | 437 | //do_equipments(); |
29 | 438 | do_styles(); |
35 | 439 | do_mash(); |
11 | 440 | |
441 | mysqli_close($db); | |
442 | ||
443 | echo "Finished adding data\n"; | |
444 | ||
445 | ||
446 | ?> |