# HG changeset patch # User Michiel Broek # Date 1549104819 -3600 # Node ID 9881453a49b3c52f49c4f038ededc3ec0e636008 # Parent 8edca0488e65016c5ff2e695622a94eddea6cc0b Recipe print and export afjusted to use array indexes. diff -r 8edca0488e65 -r 9881453a49b3 www/includes/formulas.php --- a/www/includes/formulas.php Fri Feb 01 22:00:49 2019 +0100 +++ b/www/includes/formulas.php Sat Feb 02 11:53:39 2019 +0100 @@ -181,11 +181,11 @@ */ function kw_to_srm($colormethod, $c) { - if ($colormethod == "Morey") + if ($colormethod == 0) // Morey return 1.4922 * pow($c, 0.6859); - if ($colormethod == "Mosher") + if ($colormethod == 1) // Mosher return 0.3 * $c + 4.7; - if ($colormethod == "Daniels") + if ($colormethod == 2) // Daniels return 0.2 * $c + 8.4; } @@ -205,33 +205,33 @@ global $my_factor_plug; $fmoment = 1.0; - if (($useat == "Dry Hop") || ($useat == "Dry hop") || ($useat == "Whirlpool") || ($useat == "Aroma")) { + if (($useat == 5) || ($useat == 4) || ($useat == 3)) { // Dry hop, Whirlpool or Aroma $fmoment = 0.0; - } else if ($useat == "Mash") { + } else if ($useat == 0) { // Mash $fmoment += $my_factor_mashhop / 100; // Brouwhulp - } else if (($useat == "First Wort") || ($useat == "First wort")) { + } else if ($useat == 1) { // First wort $fmoment += $my_factor_fwh / 100; // Brouwhulp, Louis, Ozzie } $pfactor = 1.0; - if ($form == "Pellet") { + if ($form == 0) { // Pellets $pfactor += $my_factor_pellet / 100; } - if ($form == "Plug") { + if ($form == 1) { // Plugs $pfactor += $my_factor_plug / 100; } $ibu = 0; - if (($method == "Tinseth") || ($method == "Garetz")) { // For Garetz, we need the $ibu + if (($method == 0) || ($method == 3)) { // Tinseth or Garetz // For Garetz, we need the $ibu $AddedAlphaAcids = (($alpha / 100) * $mass * 1000) / $volume; $Bigness_factor = 1.65 * pow( 0.000125, $sg - 1); $BoilTime_factor = ((1 - exp(-0.04 * $boiltime)) / 4.15); $utiisation = $Bigness_factor * $BoilTime_factor; $ibu = (round($utiisation * $AddedAlphaAcids * $fmoment * $pfactor * 10) / 10.0); } - if ($method == "Daniels") { + if ($method == 2) { // Daniels - if ($form == "Leaf") + if ($form == 2) // Leaf $boilfactor = -(0.0041*$boiltime*$boiltime)+(0.6162*$boiltime)+1.5779; else $boilfactor = -(0.0051*$boiltime*$boiltime)+(0.7835*$boiltime)+1.9348; @@ -241,7 +241,7 @@ $sgfactor = (($sg * 1000) - 1050) / 200; $ibu = $fmoment * (($mass * $alpha * $boilfactor * 0.1) / ($volume * (1 + $sgfactor))); } - if ($method == "Rager") { + if ($method == 1) { // Rager $boilfactor = $fmoment * 18.11 + 13.86 * tanh(($boiltime * 31.32) / 18.27); if ($sg < 1.050) $sgfactor = 0; @@ -249,7 +249,7 @@ $sgfactor = (($sg * 1000) - 1050) / 200; $ibu = ($mass * $alpha * $boilfactor * 0.1) / ($volume * (1 + $sgfactor)); } - if ($method == "Garetz") { + if ($method == 3) { // Garetz, not in use. /* Something is wrong, late hops and dryhops give negative results. */ $boilfactor = $fmoment * 6.03253 + 16.5289 * tanh(($boiltime - 19.17323) / 26.8013); $cfactor = $volume / (1.1 * $volume); // ConcentratieFactor = (Volume na koelen) / (Volume bij Koken) diff -r 8edca0488e65 -r 9881453a49b3 www/includes/global.inc.php --- a/www/includes/global.inc.php Fri Feb 01 22:00:49 2019 +0100 +++ b/www/includes/global.inc.php Sat Feb 02 11:53:39 2019 +0100 @@ -298,118 +298,4 @@ diff -r 8edca0488e65 -r 9881453a49b3 www/rec_export.php --- a/www/rec_export.php Fri Feb 01 22:00:49 2019 +0100 +++ b/www/rec_export.php Sat Feb 02 11:53:39 2019 +0100 @@ -23,6 +23,20 @@ $row = mysqli_fetch_array($result); +$recipetype = array( 'Extract', 'Partial Mash', 'All Grain' ); +$styletype = array( 'Lager', 'Ale', 'Mead', 'Wheat', 'Mixed', 'Cider' ); +$hoptype = array( 'Bittering', 'Aroma', 'Both' ); +$hopform = array( 'Pellet', 'Plug', 'Leaf' ); +$hopuse = array( 'Mash', 'First wort', 'Boil', 'Aroma', 'Whirlpool', 'Dry hop' ); +$fermentabletype = array( 'Grain', 'Sugar', 'Extract', 'Dry extract', 'Adjunct' ); +$graintype = array( 'Base', 'Roast', 'Crystal', 'Kilned', 'Sour malt', 'Special', 'No malt' ); +$yeasttype = array( 'Lager', 'Ale', 'Wheat', 'Wine', 'Champagne' ); +$yeastform = array( 'Liquid', 'Dry', 'Slant', 'Culture', 'Frozen', 'Bottle' ); +$yeastuse = array( 'Primary', 'Secondary', 'Tertiary', 'Bottle' ); +$misctype = array( 'Spice', 'Herb', 'Flavor', 'Fining', 'Water agent', 'Yeast nutrient', 'Other' ); +$miscuse = array( 'Starter', 'Mash', 'Boil', 'Primary', 'Secondary', 'Bottling' ); +$mashsteptype = array( 'Infusion', 'Temperature', 'Decoction' ); + /* * Create beerxml output @@ -50,7 +64,7 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TYPE'); -xmlwriter_text($xw, $row['type']); +xmlwriter_text($xw, $recipetype[$row['type']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'BREWER'); @@ -73,6 +87,7 @@ xmlwriter_text($xw, sprintf("%.1f",floatval($row['efficiency']))); xmlwriter_end_element($xw); + // Style xmlwriter_start_element($xw, 'STYLE'); @@ -101,7 +116,7 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TYPE'); -xmlwriter_text($xw, $row['st_type']); +xmlwriter_text($xw, $styletype[$row['st_type']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'OG_MIN'); @@ -154,6 +169,7 @@ xmlwriter_end_element($xw); // STYLE + xmlwriter_start_element($xw, 'EQUIPMENT'); xmlwriter_start_element($xw, 'VERSION'); @@ -178,6 +194,7 @@ xmlwriter_end_element($xw); // EQUIPMENT + xmlwriter_start_element($xw, 'HOPS'); $arr = json_decode($row['json_hops'], true); foreach($arr as $item) { //foreach element in $arr @@ -201,7 +218,7 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'USE'); - xmlwriter_text($xw, $item['h_useat']); + xmlwriter_text($xw, $hopuse[$item['h_useat']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TIME'); @@ -209,11 +226,11 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TYPE'); - xmlwriter_text($xw, $item['h_type']); + xmlwriter_text($xw, $hoptype[$item['h_type']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'FORM'); - xmlwriter_text($xw, $item['h_form']); + xmlwriter_text($xw, $hopform[$item['h_form']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'BETA'); @@ -232,6 +249,7 @@ } xmlwriter_end_element($xw); // HOPS + xmlwriter_start_element($xw, 'FERMENTABLES'); $arr = json_decode($row['json_fermentables'], true); foreach($arr as $item) { //foreach element in $arr @@ -246,7 +264,7 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TYPE'); - xmlwriter_text($xw, $item['f_type']); + xmlwriter_text($xw, $fermentabletype[$item['f_type']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'AMOUNT'); @@ -308,13 +326,14 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'GRAINTYPE'); - xmlwriter_text($xw, $item['f_graintype']); + xmlwriter_text($xw, $graintype[$item['f_graintype']]); xmlwriter_end_element($xw); xmlwriter_end_element($xw); // FERMENTABLE } xmlwriter_end_element($xw); // FERMENTABLES + xmlwriter_start_element($xw, 'MISCS'); $arr = json_decode($row['json_miscs'], true); foreach($arr as $item) { @@ -330,7 +349,7 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TYPE'); - xmlwriter_text($xw, $item['m_type']); + xmlwriter_text($xw, $misctype[$item['m_type']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'AMOUNT'); @@ -342,7 +361,7 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'USE'); - xmlwriter_text($xw, $item['m_use_use']); + xmlwriter_text($xw, $miscuse[$item['m_use_use']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TIME'); @@ -353,6 +372,7 @@ } xmlwriter_end_element($xw); // MISCS + xmlwriter_start_element($xw, 'YEASTS'); $arr = json_decode($row['json_yeasts'], true); foreach($arr as $item) { //foreach element in $arr @@ -368,11 +388,11 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TYPE'); - xmlwriter_text($xw, $item['y_type']); + xmlwriter_text($xw, $yeasttype[$item['y_type']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'FORM'); - xmlwriter_text($xw, $item['y_form']); + xmlwriter_text($xw, $yeastform[$item['y_form']]); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'AMOUNT'); @@ -380,7 +400,7 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'AMOUNT_IS_WEIGHT'); - ($item['y_amount_is_weight']) ? xmlwriter_text($xw, 'TRUE') : xmlwriter_text($xw, 'FALSE'); + ($item['y_form'] == 1) ? xmlwriter_text($xw, 'TRUE') : xmlwriter_text($xw, 'FALSE'); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'LABORATORY'); @@ -404,13 +424,14 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'ADD_TO_SECONDARY'); - ($item['y_use'] == 'Secondary') ? xmlwriter_text($xw, 'TRUE') : xmlwriter_text($xw, 'FALSE'); + ($item['y_use'] == 0) ? xmlwriter_text($xw, 'FALSE') : xmlwriter_text($xw, 'TRUE'); xmlwriter_end_element($xw); xmlwriter_end_element($xw); // YEAST } xmlwriter_end_element($xw); // YEASTS + xmlwriter_start_element($xw, 'WATERS'); xmlwriter_start_element($xw, 'WATER'); // Source 1 @@ -503,6 +524,7 @@ } xmlwriter_end_element($xw); // WATERS + xmlwriter_start_element($xw, 'MASH'); xmlwriter_start_element($xw, 'VERSION'); @@ -539,10 +561,10 @@ xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'TYPE'); - xmlwriter_text($xw, $item['step_type']); + xmlwriter_text($xw, $mashsteptype[$item['step_type']]); xmlwriter_end_element($xw); - if ($item['step_type'] == 'Infusion') { + if ($item['step_type'] == 0) { xmlwriter_start_element($xw, 'INFUSE_AMOUNT'); xmlwriter_text($xw, sprintf("%.1f",floatval($item['step_infuse_amount']))); xmlwriter_end_element($xw); @@ -572,6 +594,7 @@ } xmlwriter_end_element($xw); // MASH_STEPS xmlwriter_end_element($xw); // MASH + xmlwriter_end_element($xw); // RECIPE xmlwriter_end_element($xw); // RECIPES xmlwriter_end_document($xw); diff -r 8edca0488e65 -r 9881453a49b3 www/rec_print.php --- a/www/rec_print.php Fri Feb 01 22:00:49 2019 +0100 +++ b/www/rec_print.php Sat Feb 02 11:53:39 2019 +0100 @@ -97,6 +97,7 @@ global $pCara; global $colorw; global $preboil_sg; + $added = array( 'Maischen', 'Koken', 'Vergisten', 'Nagisten/lageren', 'Bottelen' ); $vul = $this->w - $this->rMargin - $this->lMargin - 132; $this->AddCol($vul,'Grondstof','L'); $this->AddCol(30,'Leverancier','L'); @@ -121,9 +122,6 @@ foreach($arr as $item) { //foreach element in $arr $name = iconv('UTF-8','windows-1252',$item['f_name']); $supplier = iconv('UTF-8','windows-1252',$item['f_supplier']); - $added = iconv('UTF-8','windows-1252',$item['f_added']); - $type = iconv('UTF-8','windows-1252',$item['f_type']); - $graintype = iconv('UTF-8','windows-1252',$item['f_graintype']); $amount = floatval($item['f_amount']); $costkg = floatval($item['f_cost']); $yield = floatval($item['f_yield']); @@ -131,9 +129,9 @@ $color = floatval($item['f_color']); $percent = floatval($item['f_percentage']); - if ($type == "Sugar") + if ($item['f_type'] == 1) // Sugar $pSugar += $percent; - if ($graintype == "Crystal") + if ($item['f_graintype'] == 2) // Crystal $pCara += $percent; $cost = $amount * $costkg; @@ -141,7 +139,7 @@ $total_fermentables += $amount; /* Calculate the amount of sugars */ $d = $amount * ($yield / 100) * (1 - $moisture / 100); - if ($added == "Mash") { + if ($item['f_added'] == 0) { // Mash $d = floatval($row['efficiency']) / 100 * $d; $sugarsm += $d; } @@ -151,7 +149,7 @@ $this->Cell($vul,5,$name,0,0,'L',true); $this->Cell(30,5,$supplier,0,0,'L',true); $this->Cell(15,5,sprintf("%.0f",$color),0,0,'R',true); - $this->Cell(17,5,added_type_names($added),0,0,'L',true); + $this->Cell(17,5,$added[$item['f_added']],0,0,'L',true); $this->Cell(20,5,sprintf("%8.3f",$amount),0,0,'R',true); $this->Cell(15,5,sprintf("%.1f%%",$percent),0,0,'R',true); $this->Cell(15,5,sprintf("%.1f%%",$yield),0,0,'R',true); @@ -177,6 +175,9 @@ global $total_ibus; global $cost_hops; global $preboil_sg; +// $hoptype = array( 'Bitterhop', 'Aromahop', 'Beide' ); + $hopform = array( 'Pellets', 'Plugs', 'Bellen' ); + $hopuse = array( 'Maischen', 'First wort', 'Koken', 'Vlamuit', 'Whirlpool', 'Koudhop' ); $vul = $this->w - $this->rMargin - $this->lMargin - 135; $this->AddCol($vul,'Hop','L'); $this->AddCol(35,'Land','L'); @@ -200,8 +201,6 @@ foreach($arr as $item) { //foreach element in $arr $name = iconv('UTF-8','windows-1252',$item['h_name']); $origin = iconv('UTF-8','windows-1252',$item['h_origin']); - $useat = iconv('UTF-8','windows-1252',$item['h_useat']); - $form = iconv('UTF-8','windows-1252',$item['h_form']); $amount = floatval($item['h_amount']) * 1000; $mass = $amount; $costkg = floatval($item['h_cost']); @@ -212,16 +211,16 @@ $cost_hops += $cost; $total_hops += $amount; - $moment = hop_useat_names($useat); - if ($useat == "Boil") { + $moment = $hopuse[$item['h_useat']]; + if ($item['h_useat'] == 2) { // Boil $moment = "Kook@".$time; } - $ibu = calc_IBU($useat, $form, /*floatval($row['est_og'])*/ $preboil_sg, floatval($row['batch_size']), $mass, $time, $alpha, $row['ibu_method']); + $ibu = calc_IBU($item['h_useat'], $item['h_form'], $preboil_sg, floatval($row['batch_size']), $mass, $time, $alpha, $row['ibu_method']); $total_ibus += $ibu; $this->Cell($vul,5,$name,0,0,'L',true); $this->Cell(35,5,$origin,0,0,'L',true); - $this->Cell(15,5,hop_form_names($form),0,0,'L',true); + $this->Cell(15,5,$hopform[$item['h_form']],0,0,'L',true); $this->Cell(20,5,$moment,0,0,'L',true); $this->Cell(15,5,sprintf("%.1f%%",$alpha),0,0,'R',true); $this->Cell(12,5,sprintf("%.1f",$ibu),0,0,'R',true); @@ -244,6 +243,8 @@ function TableYeasts($row) { global $cost_yeasts; global $svg; + $yeastform = array( 'Vloeibaar', 'Droog', 'Schuine buis', 'Slurry', 'Ingevroren', 'Depot' ); + $yeastuse = array( 'Hoofdgisting', 'Nagisting', 'Lagering', 'Bottelen' ); $vul = $this->w - $this->rMargin - $this->lMargin - 140; $this->AddCol(27,'Laboratorium','L'); $this->AddCol(18,'Product','L'); @@ -268,23 +269,21 @@ $name = iconv('UTF-8','windows-1252',$item['y_name']); $laboratory = iconv('UTF-8','windows-1252',$item['y_laboratory']); $product_id = iconv('UTF-8','windows-1252',$item['y_product_id']); - $form = iconv('UTF-8','windows-1252',$item['y_form']); - $use = iconv('UTF-8','windows-1252',$item['y_use']); $amount = floatval($item['y_amount']) * 1000; $costg = floatval($item['y_cost']); $attenuation = floatval($item['y_attenuation']); $cost = $amount * $costg; $cost_yeasts += $cost; - if ($use == "Primary") + if ($item['y_use'] == 0) // Primary $svg = $attenuation; $this->Cell(27,5,$laboratory,0,0,'L',true); $this->Cell(18,5,$product_id,0,0,'L',true); $this->Cell($vul,5,$name,0,0,'L',true); - $this->Cell(20,5,yeast_use_names($use),0,0,'L',true); + $this->Cell(20,5,$yeastuse[$item['y_use']],0,0,'L',true); $this->Cell(15,5,sprintf("%.1f%%",$attenuation),0,0,'R',true); - $this->Cell(22,5,yeast_form_names($form),0,0,'L',true); + $this->Cell(22,5,$yeastform[$item['y_form']],0,0,'L',true); $this->Cell(18,5,sprintf("%.1f",$amount),0,0,'R',true); $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); $this->Ln(); @@ -301,10 +300,12 @@ function TableMiscs($row) { global $cost_miscs; - $vul = $this->w - $this->rMargin - $this->lMargin - 95; + $misctype = array( 'Specerij', 'Kruid', 'Smaakstof', 'Klaringsmiddel', 'Brouwzout', 'Gistvoeding', 'Anders' ); + $miscuse = array( 'Starter', 'Maischen', 'Koken', 'Hoofdvergisting', 'Nagisting/lagering', 'Bottelen' ); + $vul = $this->w - $this->rMargin - $this->lMargin - 100; $this->AddCol($vul,'Naam','L'); $this->AddCol(30,'Soort','L'); - $this->AddCol(25,'Gebruik','L'); + $this->AddCol(30,'Gebruik','L'); $this->AddCol(20,'Hoeveel','R'); $this->AddCol(20,'Prijs','R'); @@ -320,8 +321,8 @@ $arr = json_decode($row['json_miscs'], true); foreach($arr as $item) { $name = iconv('UTF-8','windows-1252',$item['m_name']); - $type = iconv('UTF-8','windows-1252',$item['m_type']); - $use_use = iconv('UTF-8','windows-1252',$item['m_use_use']); + $type = $item['m_type']; + $use_use = $item['m_use_use']; $amount = floatval($item['m_amount']) * 1000; $costg = floatval($item['m_cost']) / 1000; $time = floatval($item['m_time']); @@ -329,31 +330,31 @@ $cost = $amount * $costg; $cost_miscs += $cost; - if ($type == "Water agent") + if ($type == 4) // Water agent $this->SetFillColor(240,140,130); - else if ($type == "Fining") + else if ($type == 3) // Fining $this->SetFillColor(95,180,25); - else if (($type == "Spice") || ($type == "Herb") || ($type == "Flavor") || ($type == "Yeast nutrient")) + else if (($type == 0) || ($type == 1) || ($type == 2) || ($type == 5)) // Spice, Herb, Flavour, Yeast nutrient $this->SetFillColor(240,250,65); else $this->SetFillColor(210,245,255); - if ($use_use == "Boil") - $gebruik = sprintf("%s %d min",misc_use_names($use_use),$time); + if ($use_use == 2) // Boil + $gebruik = sprintf("%s %d min",$miscuse[$use_use],$time); else - $gebruik = misc_use_names($use_use); + $gebruik = $miscuse[$use_use]; $hoeveel = sprintf("%.1f %s",$amount,$aiw ? "gr":"ml"); $this->Cell($vul,5,$name,0,0,'L',true); - $this->Cell(30,5,misc_type_names($type),0,0,'L',true); - $this->Cell(25,5,$gebruik,0,0,'L',true); + $this->Cell(30,5,$misctype[$type],0,0,'L',true); + $this->Cell(30,5,$gebruik,0,0,'L',true); $this->Cell(20,5,$hoeveel,0,0,'R',true); $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); $this->Ln(); } $this->SetFillColor(210,245,255); - $this->Cell($vul+75,5,'',0,0,'L',false); + $this->Cell($vul+80,5,'',0,0,'L',false); $this->Cell(20,5,sprintf("%8.3f",$cost_miscs).EURO,0,0,'R',true); $this->Ln(10);