183 echo " Start adding waters to the database\n"; |
183 echo " Start adding waters to the database\n"; |
184 $sql = "TRUNCATE TABLE profile_water;"; |
184 $sql = "TRUNCATE TABLE profile_water;"; |
185 if (! $result = mysqli_query($db, $sql)) { |
185 if (! $result = mysqli_query($db, $sql)) { |
186 printf("Error: %s\n", mysqli_error($db)); |
186 printf("Error: %s\n", mysqli_error($db)); |
187 } |
187 } |
188 $sql = "TRUNCATE TABLE inventory_water_sources;"; |
188 $sql = "TRUNCATE TABLE inventory_waters;"; |
189 if (! $result = mysqli_query($db, $sql)) { |
189 if (! $result = mysqli_query($db, $sql)) { |
190 printf("Error: %s\n", mysqli_error($db)); |
190 printf("Error: %s\n", mysqli_error($db)); |
191 } |
191 } |
192 |
192 |
193 $waters = simplexml_load_file($brouwhulp . '/waters.xml'); |
193 $waters = simplexml_load_file($brouwhulp . '/waters.xml'); |
195 foreach ($waters->WATER as $water) { |
195 foreach ($waters->WATER as $water) { |
196 |
196 |
197 if (($water->NAME == "Gedemineraliseerd water") || ($water->NAME == "Cristalline") || ($water->NAME == "Montille (Delhaize)") || |
197 if (($water->NAME == "Gedemineraliseerd water") || ($water->NAME == "Cristalline") || ($water->NAME == "Montille (Delhaize)") || |
198 ($water->NAME == "Spa Reine") || ($water->NAME == "Velsen") || ($water->NAME == "Zutphen") || |
198 ($water->NAME == "Spa Reine") || ($water->NAME == "Velsen") || ($water->NAME == "Zutphen") || |
199 ($water->NAME == "Aurele Bronwater (Colruyt)")) { |
199 ($water->NAME == "Aurele Bronwater (Colruyt)")) { |
200 $sql = "INSERT INTO inventory_water_sources SET name='" . mysqli_real_escape_string($db, $water->NAME); |
200 $sql = "INSERT INTO inventory_waters SET name='" . mysqli_real_escape_string($db, $water->NAME); |
201 ($water->DEFAULT_WATER == 'TRUE') ? $sql .= "', default_water='1" : $sql .= "', default_water='0"; |
201 ($water->DEFAULT_WATER == 'TRUE') ? $sql .= "', default_water='1" : $sql .= "', default_water='0"; |
202 ($water->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; |
|
203 } else { |
202 } else { |
204 $sql = "INSERT INTO profile_water SET name='" . mysqli_real_escape_string($db, $water->NAME); |
203 $sql = "INSERT INTO profile_water SET name='" . mysqli_real_escape_string($db, $water->NAME); |
205 } |
204 } |
206 |
205 |
207 if ($water->NOTES) |
206 if ($water->NOTES) |
450 |
449 |
451 foreach ($recipes->RECIPE as $recipe) { |
450 foreach ($recipes->RECIPE as $recipe) { |
452 $sql = "INSERT INTO recipes SET name='" . mysqli_real_escape_string($db, $recipe->NAME); |
451 $sql = "INSERT INTO recipes SET name='" . mysqli_real_escape_string($db, $recipe->NAME); |
453 if ($recipe->NOTES) |
452 if ($recipe->NOTES) |
454 $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES); |
453 $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES); |
|
454 else |
|
455 $sql .= "', notes='"; |
455 if ($recipe->TYPE) |
456 if ($recipe->TYPE) |
456 $sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE); |
457 $sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE); |
|
458 else |
|
459 $sql .= "', type='"; |
457 if ($recipe->BATCH_SIZE) |
460 if ($recipe->BATCH_SIZE) |
458 $sql .= "', batch_size='" . floatval($recipe->BATCH_SIZE); |
461 $sql .= "', batch_size='" . floatval($recipe->BATCH_SIZE); |
|
462 else |
|
463 $sql .= "', batch_size='20.0"; |
459 if ($recipe->BOIL_TIME) |
464 if ($recipe->BOIL_TIME) |
460 $sql .= "', boil_time='" . floatval($recipe->BOIL_TIME); |
465 $sql .= "', boil_time='" . floatval($recipe->BOIL_TIME); |
|
466 else |
|
467 $sql .= "', boil_time='90"; |
461 if ($recipe->EFFICIENCY) |
468 if ($recipe->EFFICIENCY) |
462 $sql .= "', efficiency='" . floatval($recipe->EFFICIENCY); |
469 $sql .= "', efficiency='" . floatval($recipe->EFFICIENCY); |
|
470 else |
|
471 $sql .= "', efficiency='75"; |
463 if ($recipe->EST_OG) |
472 if ($recipe->EST_OG) |
464 $sql .= "', est_og='" . floatval($recipe->EST_OG); |
473 $sql .= "', est_og='" . floatval($recipe->EST_OG); |
|
474 else |
|
475 $sql .= "', est_og='1.052"; |
465 if ($recipe->EST_FG) |
476 if ($recipe->EST_FG) |
466 $sql .= "', est_fg='" . floatval($recipe->EST_FG); |
477 $sql .= "', est_fg='" . floatval($recipe->EST_FG); |
|
478 else |
|
479 $sql .= "', est_fg='1.000"; |
467 if ($recipe->EST_COLOR) { |
480 if ($recipe->EST_COLOR) { |
468 $srm = floatval($recipe->EST_COLOR); |
481 $srm = floatval($recipe->EST_COLOR); |
469 $ebc = srm_to_ebc($srm); |
482 $ebc = srm_to_ebc($srm); |
470 $sql .= "', est_color='" . $ebc; |
483 $sql .= "', est_color='" . $ebc; |
471 } |
484 } |
540 if ($fermentable->COLOR) { |
553 if ($fermentable->COLOR) { |
541 $srm = floatval($fermentable->COLOR); |
554 $srm = floatval($fermentable->COLOR); |
542 $ebc = srm_to_ebc($srm); |
555 $ebc = srm_to_ebc($srm); |
543 $fermentables .= ',"f_color":' . $ebc; |
556 $fermentables .= ',"f_color":' . $ebc; |
544 } |
557 } |
545 if ($fermentable->COARSE_FINE_DIFF) { |
558 if ($fermentable->COARSE_FINE_DIFF) |
546 $fermentables .= ',"f_coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF); |
559 $fermentables .= ',"f_coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF); |
547 } |
560 else |
548 if ($fermentable->MOISTURE) { |
561 $fermentables .= ',"f_coarse_fine_diff":0'; |
|
562 if ($fermentable->MOISTURE) |
549 $fermentables .= ',"f_moisture":' . floatval($fermentable->MOISTURE); |
563 $fermentables .= ',"f_moisture":' . floatval($fermentable->MOISTURE); |
550 } |
564 else |
551 if ($fermentable->DIASTATIC_POWER) { |
565 $fermentables .= ',"f_moisture":0'; |
|
566 if ($fermentable->DIASTATIC_POWER) |
552 $fermentables .= ',"f_diastatic_power":' . floatval($fermentable->DIASTATIC_POWER); |
567 $fermentables .= ',"f_diastatic_power":' . floatval($fermentable->DIASTATIC_POWER); |
553 } |
568 else |
554 if ($fermentable->PROTEIN) { |
569 $fermentables .= ',"f_diastatic_power":0'; |
|
570 if ($fermentable->PROTEIN) |
555 $fermentables .= ',"f_protein":' . floatval($fermentable->PROTEIN); |
571 $fermentables .= ',"f_protein":' . floatval($fermentable->PROTEIN); |
556 } |
572 else |
557 if ($fermentable->MAX_IN_BATCH) { |
573 $fermentables .= ',"f_protein":0'; |
|
574 if ($fermentable->MAX_IN_BATCH) |
558 $fermentables .= ',"f_max_in_batch":' . floatval($fermentable->MAX_IN_BATCH); |
575 $fermentables .= ',"f_max_in_batch":' . floatval($fermentable->MAX_IN_BATCH); |
559 } |
576 else |
560 if ($fermentable->GRAINTYPE) { |
577 $fermentables .= ',"f_max_in_batch":100.0'; |
|
578 if ($fermentable->GRAINTYPE) |
561 $fermentables .= ',"f_graintype":"' . mysqli_real_escape_string($db, $fermentable->GRAINTYPE) . '"'; |
579 $fermentables .= ',"f_graintype":"' . mysqli_real_escape_string($db, $fermentable->GRAINTYPE) . '"'; |
562 } |
580 else |
563 if ($fermentable->ADDED) { |
581 $fermentables .= ',"f_graintype":"Base"'; |
|
582 if ($fermentable->ADDED) |
564 $fermentables .= ',"f_added":"' . mysqli_real_escape_string($db, $fermentable->ADDED) . '"'; |
583 $fermentables .= ',"f_added":"' . mysqli_real_escape_string($db, $fermentable->ADDED) . '"'; |
565 } |
584 else |
|
585 $fermentables .= ',"f_added":"Mash"'; |
566 ($fermentable->ADD_AFTER_BOIL== "TRUE") ? $fermentables .= ',"f_add_after_boil":true' : $fermentables .= ',"f_add_after_boil":false'; |
586 ($fermentable->ADD_AFTER_BOIL== "TRUE") ? $fermentables .= ',"f_add_after_boil":true' : $fermentables .= ',"f_add_after_boil":false'; |
567 ($fermentable->RECOMMEND_MASH== "TRUE") ? $fermentables .= ',"f_recommend_mash":true' : $fermentables .= ',"f_recommend_mash":false'; |
587 ($fermentable->RECOMMEND_MASH== "TRUE") ? $fermentables .= ',"f_recommend_mash":true' : $fermentables .= ',"f_recommend_mash":false'; |
568 if ($fermentable->DISSOLVED_PROTEIN) { |
588 if ($fermentable->DISSOLVED_PROTEIN) |
569 $fermentables .= ',"f_dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN); |
589 $fermentables .= ',"f_dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN); |
570 } |
590 else |
|
591 $fermentables .= ',"f_dissolved_protein":0'; |
571 ($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"f_adjust_to_total_100":true' : $fermentables .= ',"f_adjust_to_total_100":false'; |
592 ($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"f_adjust_to_total_100":true' : $fermentables .= ',"f_adjust_to_total_100":false'; |
572 $fermentables .= ',"f_percentage":' . floatval($fermentable->PERCENTAGE); |
593 $fermentables .= ',"f_percentage":' . floatval($fermentable->PERCENTAGE); |
573 if ($fermentable->DI_pH) { |
594 if ($fermentable->DI_pH) |
574 $fermentables .= ',"f_di_ph":' . floatval($fermentable->DI_pH); |
595 $fermentables .= ',"f_di_ph":' . floatval($fermentable->DI_pH); |
575 } |
596 else |
|
597 $fermentables .= ',"f_di_ph":5.6'; |
576 $fermentables .= "}"; |
598 $fermentables .= "}"; |
577 } |
599 } |
578 |
600 |
579 $fermentables .= ']'; |
601 $fermentables .= ']'; |
580 // echo $fermentables . PHP_EOL; |
602 // echo $fermentables . PHP_EOL; |