www/import/from_brouwhulp.php

changeset 234
b8b5efa495bb
parent 230
8edca0488e65
child 246
8580a08cbaa7
equal deleted inserted replaced
233:14a84d42031d 234:b8b5efa495bb
1173 $efficiency = floatval($recipe->EFFICIENCY); 1173 $efficiency = floatval($recipe->EFFICIENCY);
1174 $sql .= "', efficiency='" . $efficiency; 1174 $sql .= "', efficiency='" . $efficiency;
1175 /* Don't use $recipe->EST_OG but recalculate it */ 1175 /* Don't use $recipe->EST_OG but recalculate it */
1176 /* Don't use $recipe->EST_FG but recalculate it */ 1176 /* Don't use $recipe->EST_FG but recalculate it */
1177 /* Don't use $recipe->EST_COLOR but recalculate it */ 1177 /* Don't use $recipe->EST_COLOR but recalculate it */
1178 if ($recipe->COLOR_METHOD == 'Morey') 1178 $color_method = 0;
1179 if ($recipe->COLOR_METHOD == 'Morey') {
1180 $color_method = 0;
1179 $sql .= "', color_method='0"; 1181 $sql .= "', color_method='0";
1180 else if ($recipe->COLOR_METHOD == 'Mosher') 1182 } else if ($recipe->COLOR_METHOD == 'Mosher') {
1183 $color_method = 1;
1181 $sql .= "', color_method='1"; 1184 $sql .= "', color_method='1";
1182 else if ($recipe->COLOR_METHOD == 'Daniels') 1185 } else if ($recipe->COLOR_METHOD == 'Daniels') {
1186 $color_method = 2;
1183 $sql .= "', color_method='2"; 1187 $sql .= "', color_method='2";
1184 else 1188 } else
1185 echo "Unknown COLOR_METHO " . $recipe->COLOR_METHOD . PHP_EOL; 1189 echo "Unknown COLOR_METHO " . $recipe->COLOR_METHOD . PHP_EOL;
1186 1190
1187 if ($recipe->IBU) 1191 if ($recipe->IBU)
1188 $sql .= "', est_ibu='" . floatval($recipe->IBU); 1192 $sql .= "', est_ibu='" . floatval($recipe->IBU);
1189 if ($recipe->IBU_METHOD == 'Tinseth') 1193 if ($recipe->IBU_METHOD == 'Tinseth')
1299 $sql .= "', est_og='" . floatval($og); 1303 $sql .= "', est_og='" . floatval($og);
1300 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og); 1304 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og);
1301 $sql .= "', est_fg='" . floatval($fg); 1305 $sql .= "', est_fg='" . floatval($fg);
1302 $abv = abvol($og, $fg); 1306 $abv = abvol($og, $fg);
1303 $sql .= "', est_abv='" . floatval($abv); 1307 $sql .= "', est_abv='" . floatval($abv);
1304 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw); 1308 $color = kw_to_ebc($color_method, $colorw);
1305 $sql .= "', est_color='" . floatval($color); 1309 $sql .= "', est_color='" . floatval($color);
1306 $sql .= "';"; 1310 $sql .= "';";
1307 if (! $result = mysqli_query($db, $sql)) { 1311 if (! $result = mysqli_query($db, $sql)) {
1308 printf("Error: %s\n", mysqli_error($db)); 1312 printf("Error: %s\n", mysqli_error($db));
1309 } 1313 }
1322 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $colorw, $f_sugars; 1326 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $colorw, $f_sugars;
1323 $len_fermentables = 0; 1327 $len_fermentables = 0;
1324 $len_hops = 0; 1328 $len_hops = 0;
1325 $len_miscs = 0; 1329 $len_miscs = 0;
1326 $len_yeasts = 0; 1330 $len_yeasts = 0;
1327 $len_mash = 0; 1331 $len_mash = 0;
1328 1332
1329 echo " Start adding brews to the database\n"; 1333 echo " Start adding brews to the database\n";
1330 $sql = "TRUNCATE TABLE products;"; 1334 $sql = "TRUNCATE TABLE products;";
1331 if (! $presult = mysqli_query($db, $sql)) { 1335 if (! $presult = mysqli_query($db, $sql)) {
1332 printf("Error: %s\n", mysqli_error($db)); 1336 printf("Error: %s\n", mysqli_error($db));
1342 $boil_size = 22; 1346 $boil_size = 22;
1343 $pCara = 0; 1347 $pCara = 0;
1344 $pSugar = 0; 1348 $pSugar = 0;
1345 $svg = 77; 1349 $svg = 77;
1346 $colorw = 0; 1350 $colorw = 0;
1347 $stageno = 0; 1351 $stage = 0;
1348 $stage = "Plan"; // Default value.
1349 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid')); 1352 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
1350 1353
1351 $sql = "INSERT INTO products SET uuid='" . $uuid; 1354 $sql = "INSERT INTO products SET uuid='" . $uuid;
1352 $sql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME); 1355 $sql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
1353 1356
1354 if ($recipe->NOTES) { 1357 if ($recipe->NOTES) {
1355 $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES); 1358 $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES);
1356 } else { 1359 } else {
1357 $sql .= "', notes='"; 1360 $sql .= "', notes='";
1358 } 1361 }
1359 if ($recipe->TYPE) 1362
1360 $sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE); 1363 if ($recipe->TYPE == 'Extract')
1361 else 1364 $sql .= "', type='0";
1362 $sql .= "', type='"; 1365 else if ($recipe->TYPE == 'Partial Mash')
1366 $sql .= "', type='1";
1367 else if ($recipe->TYPE == 'All Grain')
1368 $sql .= "', type='2";
1369
1363 if ($recipe->BATCH_SIZE) 1370 if ($recipe->BATCH_SIZE)
1364 $batch_size = floatval($recipe->BATCH_SIZE); 1371 $batch_size = floatval($recipe->BATCH_SIZE);
1365 $sql .= "', batch_size='" . $batch_size; 1372 $sql .= "', batch_size='" . $batch_size;
1366 if ($recipe->BOIL_SIZE) 1373 if ($recipe->BOIL_SIZE)
1367 $boil_size = floatval($recipe->BOIL_SIZE); 1374 $boil_size = floatval($recipe->BOIL_SIZE);
1373 if ($recipe->EFFICIENCY) 1380 if ($recipe->EFFICIENCY)
1374 $efficiency = floatval($recipe->EFFICIENCY); 1381 $efficiency = floatval($recipe->EFFICIENCY);
1375 $sql .= "', efficiency='" . $efficiency; 1382 $sql .= "', efficiency='" . $efficiency;
1376 /* Don't use $recipe->EST_OG but recalculate it */ 1383 /* Don't use $recipe->EST_OG but recalculate it */
1377 /* Don't use $recipe->EST_FG but recalculate it */ 1384 /* Don't use $recipe->EST_FG but recalculate it */
1378 /* Don't use $recipe->EST_COLOR but recalculate it */ 1385 /* Don't use $recipe->EST_COLOR but recalculate it */
1379 if ($recipe->COLOR_METHOD) 1386 $color_method = 0;
1380 $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD); 1387 if ($recipe->COLOR_METHOD == 'Morey') {
1381 if ($recipe->IBU) 1388 $color_method = 0;
1382 $sql .= "', est_ibu='" . floatval($recipe->IBU); 1389 $sql .= "', color_method='0";
1383 if ($recipe->IBU_METHOD) 1390 } else if ($recipe->COLOR_METHOD == 'Mosher') {
1384 $sql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD); 1391 $color_method = 1;
1392 $sql .= "', color_method='1";
1393 } else if ($recipe->COLOR_METHOD == 'Daniels') {
1394 $color_method = 2;
1395 $sql .= "', color_method='2";
1396 } else
1397 echo "Unknown COLOR_METHO " . $recipe->COLOR_METHOD . PHP_EOL;
1398
1399 if ($recipe->IBU)
1400 $sql .= "', est_ibu='" . floatval($recipe->IBU);
1401 if ($recipe->IBU_METHOD == 'Tinseth')
1402 $sql .= "', ibu_method='0";
1403 else if ($recipe->IBU_METHOD == 'Rager')
1404 $sql .= "', ibu_method='1";
1405 else if ($recipe->IBU_METHOD == 'Daniels')
1406 $sql .= "', ibu_method='2";
1407 else
1408 echo "Unknown IBU_METHOD " . $recipe->IBU_METHOD . PHP_EOL;
1409
1385 if ($recipe->CARBONATION) 1410 if ($recipe->CARBONATION)
1386 $sql .= "', est_carb='" . floatval($recipe->CARBONATION); 1411 $sql .= "', est_carb='" . floatval($recipe->CARBONATION);
1387 1412
1388 if ($recipe->STYLE) { 1413 if ($recipe->STYLE) {
1389 $sql .= recipe_style($recipe); 1414 $sql .= recipe_style($recipe);
1394 } 1419 }
1395 if ($recipe->TARGET_PH) { 1420 if ($recipe->TARGET_PH) {
1396 $sql .= "', mash_ph='" . floatval($recipe->TARGET_PH); 1421 $sql .= "', mash_ph='" . floatval($recipe->TARGET_PH);
1397 } 1422 }
1398 if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Lactic")) { 1423 if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Lactic")) {
1399 $sql .= "', sparge_acid_type='Melkzuur"; 1424 $sql .= "', sparge_acid_type='0";
1400 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Hydrochloric")) { 1425 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Hydrochloric")) {
1401 $sql .= "', sparge_acid_type='Zoutzuur"; 1426 $sql .= "', sparge_acid_type='1";
1402 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Phosphoric")) { 1427 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Phosphoric")) {
1403 $sql .= "', sparge_acid_type='Fosforzuur"; 1428 $sql .= "', sparge_acid_type='2";
1404 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Sulfuric")) { 1429 } else if ($recipe->SPARGE_ACID_TYPE && ($recipe->SPARGE_ACID_TYPE == "Sulfuric")) {
1405 $sql .= "', sparge_acid_type='Zwavelzuur"; 1430 $sql .= "', sparge_acid_type='3";
1406 } 1431 }
1407 if ($recipe->ACID_SPARGE_PERC) { 1432 if ($recipe->ACID_SPARGE_PERC) {
1408 $sql .= "', sparge_acid_perc='" . floatval($recipe->ACID_SPARGE_PERC); 1433 $sql .= "', sparge_acid_perc='" . floatval($recipe->ACID_SPARGE_PERC);
1409 } 1434 }
1410 if ($recipe->LACTIC_SPARGE) { 1435 if ($recipe->LACTIC_SPARGE) {
1487 $sql .= "', est_og='" . floatval($og); 1512 $sql .= "', est_og='" . floatval($og);
1488 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og); 1513 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og);
1489 $sql .= "', est_fg='" . floatval($fg); 1514 $sql .= "', est_fg='" . floatval($fg);
1490 $abv = abvol($og, $fg); 1515 $abv = abvol($og, $fg);
1491 $sql .= "', est_abv='" . floatval($abv); 1516 $sql .= "', est_abv='" . floatval($abv);
1492 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw); 1517 $color = kw_to_ebc($color_method, $colorw);
1493 $sql .= "', est_color='" . floatval($color); 1518 $sql .= "', est_color='" . floatval($color);
1494 $sql .= "', code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE); 1519 $sql .= "', code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE);
1495 1520
1496 /* 1521 /*
1497 * Update external logfiles 1522 * Update external logfiles
1503 } 1528 }
1504 $count = mysqli_affected_rows($db); 1529 $count = mysqli_affected_rows($db);
1505 if ($count > 0) { 1530 if ($count > 0) {
1506 $sql .= "', log_brew='1"; 1531 $sql .= "', log_brew='1";
1507 } 1532 }
1508 $lsql = "UPDATE log_fermentation SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME); 1533
1509 $lsql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';"; 1534 $filename = '../log/fermentation/'.$recipe->NR_RECIPE.' '.$recipe->NAME.'.log';
1510 if (! $result = mysqli_query($db, $lsql)) { 1535 if (file_exists($filename)) {
1511 printf("Error: %s\n", mysqli_error($db));
1512 }
1513 $count = mysqli_affected_rows($db);
1514 if ($count > 0) {
1515 $sql .= "', log_fermentation='1"; 1536 $sql .= "', log_fermentation='1";
1516 } else { 1537 } else {
1517 // See if there really are no records 1538 if ($recipe->FERM_MEASUREMENTS) {
1518 $lsql = "SELECT product_code FROM log_fermentation WHERE product_code='".$recipe->NR_RECIPE."';"; 1539 /*
1519 $count = mysqli_affected_rows($db); 1540 * There is internal logdata in the xml, create a logfile
1520 if ($count > 0) { 1541 */
1542 $fp = fopen($filename, "w+");
1543 foreach ($recipe->FERM_MEASUREMENTS->FERM_MEASUREMENT as $measurement) {
1544 $dt = substr($measurement->DATE_TIME, 6, 4).substr($measurement->DATE_TIME,2,4).substr($measurement->DATE_TIME,0,2);
1545 $dt .= ' '.substr($measurement->DATE_TIME, 11,8);
1546 $line = $dt.',NONE,PRIMARY,';
1547 $line .= sprintf("%.1f",floatval($measurement->TEMP_SENSOR_1)) .',';
1548 $line .= sprintf("%.1f",floatval($measurement->TEMP_SENSOR_2)) .',';
1549 $line .= 'NA,NA,NA,NA,NA,NA,NA,NA,' . PHP_EOL;
1550 fwrite($fp, $line);
1551 }
1552 fclose($fp);
1521 $sql .= "', log_fermentation='1"; 1553 $sql .= "', log_fermentation='1";
1554 } else {
1555 $sql .= "', log_fermentation='0";
1522 } 1556 }
1523 }
1524
1525 /*
1526 * If no external fermentation log is found, check for an internal one.
1527 */
1528 if (($count == 0) && $recipe->FERM_MEASUREMENTS) {
1529 $lsql = "DELETE FROM log_fermentation WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
1530 if (! $lresult = mysqli_query($db, $lsql)) {
1531 printf("Error: %s\n", mysqli_error($db));
1532 }
1533 foreach ($recipe->FERM_MEASUREMENTS->FERM_MEASUREMENT as $measurement) {
1534 $dt = substr($measurement->DATE_TIME, 6, 4).substr($measurement->DATE_TIME,2,4).substr($measurement->DATE_TIME,0,2);
1535 $dt .= ' '.substr($measurement->DATE_TIME, 11,8);
1536 $lsql = "INSERT INTO log_fermentation SET product_uuid='".$uuid;
1537 $lsql .= "', product_code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE);
1538 $lsql .= "', product_name='" . mysqli_real_escape_string($db, $recipe->NAME);
1539 $lsql .= "', datetime='" . $dt;
1540 $lsql .= "', temperature_air='" . floatval($measurement->TEMP_SENSOR_1);
1541 $lsql .= "', temperature_beer='" . floatval($measurement->TEMP_SENSOR_2);
1542 $lsql .= "';";
1543 if (! $lresult = mysqli_query($db, $lsql)) {
1544 printf("Error: %s\n", mysqli_error($db));
1545 }
1546 }
1547 $sql .= "', log_fermentation='1";
1548 } 1557 }
1549 1558
1550 if ($recipe->EQUIPMENT) { 1559 if ($recipe->EQUIPMENT) {
1551 $sql .= "', eq_name='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NAME); 1560 $sql .= "', eq_name='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NAME);
1552 $sql .= "', eq_notes='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NOTES); 1561 $sql .= "', eq_notes='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NOTES);
1553 $sql .= "', eq_boil_size='" . floatval($recipe->EQUIPMENT->BOIL_SIZE); 1562 $sql .= "', eq_boil_size='" . floatval($recipe->EQUIPMENT->BOIL_SIZE);
1554 $sql .= "', eq_batch_size='" . floatval($recipe->EQUIPMENT->BATCH_SIZE); 1563 $sql .= "', eq_batch_size='" . floatval($recipe->EQUIPMENT->BATCH_SIZE);
1555 $sql .= "', eq_tun_volume='" . floatval($recipe->EQUIPMENT->TUN_VOLUME); 1564 $sql .= "', eq_tun_volume='" . floatval($recipe->EQUIPMENT->TUN_VOLUME);
1556 $sql .= "', eq_tun_weight='" . floatval($recipe->EQUIPMENT->TUN_WEIGHT); 1565 $sql .= "', eq_tun_weight='" . floatval($recipe->EQUIPMENT->TUN_WEIGHT);
1557 $sql .= "', eq_tun_specific_heat='" . floatval($recipe->EQUIPMENT->TUN_SPECIFIC_HEAT); 1566 $sql .= "', eq_tun_specific_heat='" . floatval($recipe->EQUIPMENT->TUN_SPECIFIC_HEAT);
1558 $sql .= "', eq_tun_material='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->TUN_MATERIAL); 1567 $sql .= "', eq_tun_material='" . $recipe->EQUIPMENT->TUN_MATERIAL;
1559 $sql .= "', eq_tun_height='" . floatval($recipe->EQUIPMENT->TUN_HEIGHT); 1568 $sql .= "', eq_tun_height='" . floatval($recipe->EQUIPMENT->TUN_HEIGHT);
1560 if ($recipe->EQUIPMENT->TOP_UP_WATER) 1569 if ($recipe->EQUIPMENT->TOP_UP_WATER)
1561 $sql .= "', eq_top_up_water='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER); 1570 $sql .= "', eq_top_up_water='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER);
1562 $sql .= "', eq_trub_chiller_loss='" . floatval($recipe->EQUIPMENT->TRUB_CHILLER_LOSS); 1571 $sql .= "', eq_trub_chiller_loss='" . floatval($recipe->EQUIPMENT->TRUB_CHILLER_LOSS);
1563 /* 1572 /*
1583 } 1592 }
1584 1593
1585 if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) { 1594 if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) {
1586 /* We have a plan date but haven't brewed yet, use current date */ 1595 /* We have a plan date but haven't brewed yet, use current date */
1587 $sql .= "', birth='" . date("Y-m-d"); 1596 $sql .= "', birth='" . date("Y-m-d");
1588 $stageno= 1; 1597 $stage = 1;
1589 $stage = "Wait";
1590 } 1598 }
1591 1599
1592 if (($recipe->DATE) && ($recipe->TIME_STARTED) && ($recipe->TIME_ENDED)) { 1600 if (($recipe->DATE) && ($recipe->TIME_STARTED) && ($recipe->TIME_ENDED)) {
1593 /* We have brew data */ 1601 /* We have brew data */
1594 $stageno = 3; 1602 $stage = 3; // Need to think about during a brew...
1595 $stage = "Primary"; // Need to think about during a brew...
1596 $brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2); 1603 $brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2);
1597 $sql .= "', birth='" . $brewdate; 1604 $sql .= "', birth='" . $brewdate;
1598 $date_start = $brewdate.' '.$recipe->TIME_STARTED; 1605 $date_start = $brewdate.' '.$recipe->TIME_STARTED;
1599 $date_end = $brewdate.' '.$recipe->TIME_ENDED; 1606 $date_end = $brewdate.' '.$recipe->TIME_ENDED;
1600 $sql .= "', brew_date_start='" . $date_start; 1607 $sql .= "', brew_date_start='" . $date_start;
1621 if ($recipe->PH_AFTER_BOIL) 1628 if ($recipe->PH_AFTER_BOIL)
1622 $sql .= "', brew_aboil_ph='" . floatval($recipe->PH_AFTER_BOIL); 1629 $sql .= "', brew_aboil_ph='" . floatval($recipe->PH_AFTER_BOIL);
1623 if ($recipe->ACTUAL_EFFICIENCY) 1630 if ($recipe->ACTUAL_EFFICIENCY)
1624 $sql .= "', brew_aboil_efficiency='" . floatval($recipe->ACTUAL_EFFICIENCY); 1631 $sql .= "', brew_aboil_efficiency='" . floatval($recipe->ACTUAL_EFFICIENCY);
1625 $sql .= "', brew_whirlpool2='" . floatval($recipe->WHIRLPOOL_TIME); 1632 $sql .= "', brew_whirlpool2='" . floatval($recipe->WHIRLPOOL_TIME);
1626 $sql .= "', brew_cooling_method='" . mysqli_real_escape_string($db, $recipe->COOLING_METHOD); 1633
1634 if ($recipe->COOLING_METHOD == '-')
1635 $sql .= "', brew_cooling_method='0";
1636 else if ($recipe->COOLING_METHOD == 'Emersion chiller')
1637 $sql .= "', brew_cooling_method='1";
1638 else if ($recipe->COOLING_METHOD == 'Counterflow chiller')
1639 $sql .= "', brew_cooling_method='2";
1640 else if ($recipe->COOLING_METHOD == 'Au bain marie')
1641 $sql .= "', brew_cooling_method='3";
1642 else if ($recipe->COOLING_METHOD == 'Natural')
1643 $sql .= "', brew_cooling_method='4";
1644 else
1645 echo "Unknown COOLING_METHOD " . $recipe->COOLING_METHOD . PHP_EOL;
1627 $sql .= "', brew_cooling_time='" . floatval($recipe->COOLING_TIME); 1646 $sql .= "', brew_cooling_time='" . floatval($recipe->COOLING_TIME);
1628 $sql .= "', brew_cooling_to='" . floatval($recipe->COOLING_TO); 1647 $sql .= "', brew_cooling_to='" . floatval($recipe->COOLING_TO);
1629 if ($recipe->VOLUME_FERMENTER) 1648 if ($recipe->VOLUME_FERMENTER)
1630 $sql .= "', brew_fermenter_volume='" . floatval($recipe->VOLUME_FERMENTER); 1649 $sql .= "', brew_fermenter_volume='" . floatval($recipe->VOLUME_FERMENTER);
1631 if ($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY) 1650 if ($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY)
1632 $sql .= "', brew_fermenter_extrawater='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY); 1651 $sql .= "', brew_fermenter_extrawater='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY);
1633 $sql .= "', brew_fermenter_sg='" . floatval($recipe->OG_FERMENTER); 1652 $sql .= "', brew_fermenter_sg='" . floatval($recipe->OG_FERMENTER);
1634 $sql .= "', brew_fermenter_ibu='" . floatval($recipe->IBU); 1653 $sql .= "', brew_fermenter_ibu='" . floatval($recipe->IBU);
1635 $sql .= "', brew_aeration_type='" . mysqli_real_escape_string($db, $recipe->AERATION_TYPE); 1654
1636 if ($recipe->AERATION_TYPE != "None") { 1655 if ($recipe->AERATION_TYPE == 'None')
1656 $sql .= "', brew_aeration_type='0";
1657 else if ($recipe->AERATION_TYPE == 'Air') {
1658 $sql .= "', brew_aeration_type='1";
1637 $sql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED); 1659 $sql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED);
1638 $sql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME); 1660 $sql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME);
1639 } 1661 } else if ($recipe->AERATION_TYPE == 'Oxygen') {
1662 $sql .= "', brew_aeration_type='2";
1663 $sql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED);
1664 $sql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME);
1665 } else
1666 echo "Unknown AERATION_TYPE " . $recipe->AERATION_TYPE . PHP_EOL;
1667
1640 $sql .= "', brew_date_end='" . $date_end; 1668 $sql .= "', brew_date_end='" . $date_end;
1641 } 1669 }
1642 1670
1643 $sql .= "', og='" . floatval($recipe->OG); 1671 $sql .= "', og='" . floatval($recipe->OG);
1644 $sql .= "', fg='" . floatval($recipe->FG); 1672 $sql .= "', fg='" . floatval($recipe->FG);
1645 1673
1646 if ($recipe->PRIMARY_AGE && ($stageno >= 3)) { 1674 if ($recipe->PRIMARY_AGE && ($stage >= 3)) {
1647 /* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */ 1675 /* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */
1648 $pdate = new DateTime($brewdate); 1676 $pdate = new DateTime($brewdate);
1649 $pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days"); 1677 $pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days");
1650 $sql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY); 1678 $sql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY);
1651 $sql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY); 1679 $sql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY);
1652 $sql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY); 1680 $sql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY);
1653 $sql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY); 1681 $sql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY);
1654 $sql .= "', primary_end_date='" . $pdate->format("Y-m-d"); 1682 $sql .= "', primary_end_date='" . $pdate->format("Y-m-d");
1655 $stageno = 4; 1683 $stage = 4; // Secondary
1656 $stage = "Secondary"; 1684
1657 1685 if ($recipe->SECONDARY_AGE && ($stage >= 4)) {
1658 if ($recipe->SECONDARY_AGE && ($stageno >= 4)) {
1659 $sdate = new DateTime($brewdate); 1686 $sdate = new DateTime($brewdate);
1660 $sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days"); 1687 $sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days");
1661 $sql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP); 1688 $sql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP);
1662 $sql .= "', secondary_end_date='" . $sdate->format("Y-m-d"); 1689 $sql .= "', secondary_end_date='" . $sdate->format("Y-m-d");
1663 $stageno = 5; 1690 $stage = 5; // Tertiary
1664 $stage = "Tertiary"; 1691
1665 1692 if ($recipe->TERTIARY_TEMP && ($stage >= 5)) {
1666 if ($recipe->TERTIARY_TEMP && ($stageno >= 5)) {
1667 $sql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP); 1693 $sql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP);
1668 } 1694 }
1669 } 1695 }
1670 } 1696 }
1671 1697
1672 if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) && 1698 if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) &&
1673 ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS) && ($stageno >= 5)) { 1699 ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS) && ($stage >= 5)) {
1674 $bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2); 1700 $bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2);
1675 $sql .= "', package_date='" . $bdate; 1701 $sql .= "', package_date='" . $bdate;
1676 $stage = "Package"; 1702 $stage = 6; // Package
1677 $stageno = 6;
1678 $dStart = new DateTime($bdate); 1703 $dStart = new DateTime($bdate);
1679 $dEnd = new DateTime(''); 1704 $dEnd = new DateTime('');
1680 $dDiff = $dStart->diff($dEnd); 1705 $dDiff = $dStart->diff($dEnd);
1681 $age = floatval($dDiff->days); 1706 $age = floatval($dDiff->days);
1682 if ($age == 0) { // Package day 1707 if ($age == 0) { // Package day
1683 $stage = "Package"; 1708 $stage = 6;
1684 $stageno = 6;
1685 } else if ($age < 14) { // Carbonation period 1709 } else if ($age < 14) { // Carbonation period
1686 $stage = "Carbonation"; 1710 $stage = 7;
1687 $stageno = 7;
1688 } else if ($age < 42) { // Mature, fixed 6 weeks 1711 } else if ($age < 42) { // Mature, fixed 6 weeks
1689 $stage = "Mature"; 1712 $stage = 8;
1690 $stageno = 8;
1691 } else { // Ready for tasting. 1713 } else { // Ready for tasting.
1692 $stage = "Taste"; 1714 $stage = 9;
1693 $stageno = 9;
1694 } 1715 }
1695 1716
1696 if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) { 1717 if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) {
1697 $sql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING); 1718 $sql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING);
1698 $sql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION); 1719 $sql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION);
1720
1699 if ($recipe->PRIMING_SUGAR_BOTTLES == "Saccharose") 1721 if ($recipe->PRIMING_SUGAR_BOTTLES == "Saccharose")
1700 $sql .= "', bottle_priming_sugar='Kristalsuiker"; 1722 $sql .= "', bottle_priming_sugar='0";
1701 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Glucose or dextrose") 1723 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Glucose or dextrose")
1702 $sql .= "', bottle_priming_sugar='Glucose/dextrose"; 1724 $sql .= "', bottle_priming_sugar='1";
1703 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Honey") 1725 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Honey")
1704 $sql .= "', bottle_priming_sugar='Honing"; 1726 $sql .= "', bottle_priming_sugar='2";
1705 else if ($recipe->PRIMING_SUGAR_BOTTLES == "DME") 1727 else if ($recipe->PRIMING_SUGAR_BOTTLES == "DME")
1706 $sql .= "', bottle_priming_sugar='Moutextract"; 1728 $sql .= "', bottle_priming_sugar='3";
1707 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Molassis") 1729 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Molassis")
1708 $sql .= "', bottle_priming_sugar='Melasse"; 1730 $sql .= "', bottle_priming_sugar='4";
1709 $sql .= "', bottle_priming_amount='" . floatval($recipe->AMOUNT_PRIMING); 1731 $sql .= "', bottle_priming_amount='" . floatval($recipe->AMOUNT_PRIMING);
1710 $sql .= "', bottle_carbonation_temp='" . floatval($recipe->CARBONATION_TEMP); 1732 $sql .= "', bottle_carbonation_temp='" . floatval($recipe->CARBONATION_TEMP);
1711 } 1733 }
1712 if ($recipe->AMOUNT_KEGGED && $recipe->AMOUNT_PRIMING_KEGS) { 1734 if ($recipe->AMOUNT_KEGGED && $recipe->AMOUNT_PRIMING_KEGS) {
1713 $sql .= "', keg_amount='" . floatval($recipe->AMOUNT_KEGGED); 1735 $sql .= "', keg_amount='" . floatval($recipe->AMOUNT_KEGGED);
1714 $sql .= "', keg_carbonation='" . floatval($recipe->CARBONATION); // Lijkt wel hetzelfde als bottles 1736 $sql .= "', keg_carbonation='" . floatval($recipe->CARBONATION); // Lijkt wel hetzelfde als bottles
1715 if ($recipe->PRIMING_SUGAR_BOTTLES == "Saccharose") 1737 if ($recipe->PRIMING_SUGAR_BOTTLES == "Saccharose")
1716 $sql .= "', keg_priming_sugar='Kristalsuiker"; 1738 $sql .= "', keg_priming_sugar='0";
1717 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Glucose or dextrose") 1739 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Glucose or dextrose")
1718 $sql .= "', keg_priming_sugar='Glucose/dextrose"; 1740 $sql .= "', keg_priming_sugar='1";
1719 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Honey") 1741 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Honey")
1720 $sql .= "', keg_priming_sugar='Honing"; 1742 $sql .= "', keg_priming_sugar='2";
1721 else if ($recipe->PRIMING_SUGAR_BOTTLES == "DME") 1743 else if ($recipe->PRIMING_SUGAR_BOTTLES == "DME")
1722 $sql .= "', keg_priming_sugar='Moutextract"; 1744 $sql .= "', keg_priming_sugar='3";
1723 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Molassis") 1745 else if ($recipe->PRIMING_SUGAR_BOTTLES == "Molassis")
1724 $sql .= "', keg_priming_sugar='Melasse"; 1746 $sql .= "', keg_priming_sugar='4";
1725 $sql .= "', keg_priming_amount='" . floatval($recipe->AMOUNT_PRIMING_KEGS); 1747 $sql .= "', keg_priming_amount='" . floatval($recipe->AMOUNT_PRIMING_KEGS);
1726 $sql .= "', keg_carbonation_temp='" . floatval($recipe->KEG_CARB_TEMP); 1748 $sql .= "', keg_carbonation_temp='" . floatval($recipe->KEG_CARB_TEMP);
1727 ($recipe->FORCED_CARB_KEGS == 'TRUE') ? $sql .= "', keg_forced_carb='1" : $sql .= "', keg_forced_carb='0"; 1749 ($recipe->FORCED_CARB_KEGS == 'TRUE') ? $sql .= "', keg_forced_carb='1" : $sql .= "', keg_forced_carb='0";
1728 $sql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE); 1750 $sql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE);
1729 } 1751 }
1730 } 1752 }
1731 1753
1732 if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE && ($stageno >= 9)) { 1754 if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE && ($stage >= 9)) {
1733 $stage = "Ready"; // Ready if tasted. 1755 $stage = 10; // Ready
1734 $stageno = 10;
1735 $sql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES); 1756 $sql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES);
1736 $sql .= "', taste_rate='" . floatval($recipe->TASTING_RATE); 1757 $sql .= "', taste_rate='" . floatval($recipe->TASTING_RATE);
1737 $tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2); 1758 $tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2);
1738 $sql .= "', taste_date='" . $tdate; 1759 $sql .= "', taste_date='" . $tdate;
1739 $sql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR); 1760 $sql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR);
1744 $sql .= "', taste_mouthfeel='" . mysqli_real_escape_string($db, $recipe->TASTE_MOUTHFEEL); 1765 $sql .= "', taste_mouthfeel='" . mysqli_real_escape_string($db, $recipe->TASTE_MOUTHFEEL);
1745 $sql .= "', taste_aftertaste='" . mysqli_real_escape_string($db, $recipe->TASTE_AFTERTASTE); 1766 $sql .= "', taste_aftertaste='" . mysqli_real_escape_string($db, $recipe->TASTE_AFTERTASTE);
1746 } 1767 }
1747 1768
1748 ($recipe->INVENTORY_REDUCED == 'TRUE') ? $sql .= "', inventory_reduced='1" : $sql .= "', inventory_reduced='0"; 1769 ($recipe->INVENTORY_REDUCED == 'TRUE') ? $sql .= "', inventory_reduced='1" : $sql .= "', inventory_reduced='0";
1749 if (($recipe->LOCKED == 'TRUE') && ($stage == 'Ready')) { 1770 if (($recipe->LOCKED == 'TRUE') && ($stage == 10)) {
1750 $sql .= "', locked='1"; 1771 $sql .= "', locked='1";
1751 $stage = "Closed"; 1772 $stage = 11;
1752 $stageno = 11;
1753 } else { 1773 } else {
1754 $sql .= "', locked='0"; 1774 $sql .= "', locked='0";
1755 } 1775 }
1756 1776
1757 $sql .= "', stage='" . $stage; 1777 $sql .= "', stage='" . $stage;

mercurial