<?php require_once('../Connections/config.php'); 
include('../includes/db_connect_universal.inc.php');
include('../includes/check_mobile.inc.php');
include('../includes/plug-ins.inc.php');

$colname_log = "-1";
if (isset($_GET['id'])) {
	if (is_numeric($_GET['id'])) {
  			$colname_log = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
	}
	else { echo "Not a valid request."; die;  }

}
$source = "1";
if (isset($_GET['source'])) {
  $source = (get_magic_quotes_gpc()) ? $_GET['source'] : addslashes($_GET['source']);
}

if ($source == "brewLog") {
mysql_select_db($database_brewing, $brewing);
$query_log = sprintf("SELECT * FROM brewing WHERE id = '%s'", $colname_log);
$log = mysql_query($query_log, $brewing) or die(mysql_error());
$row_log = mysql_fetch_assoc($log);
$totalRows_log = mysql_num_rows($log);

$query_mash_profiles = sprintf("SELECT * FROM mash_profiles WHERE id='%s'", $row_log['brewMashProfile']);
$mash_profiles = mysql_query($query_mash_profiles, $brewing) or die(mysql_error());
$row_mash_profiles = mysql_fetch_assoc($mash_profiles);
$totalRows_mash_profiles = mysql_num_rows($mash_profiles);

$query_mash_steps = sprintf("SELECT * FROM mash_steps WHERE stepMashProfileID = '%s'", $row_mash_profiles['id']);
$mash_steps = mysql_query($query_mash_steps, $brewing) or die(mysql_error());
$row_mash_steps = mysql_fetch_assoc($mash_steps);
$totalRows_mash_steps = mysql_num_rows($mash_steps);

$query_water_profiles = sprintf("SELECT * FROM water_profiles WHERE id='%s'", $row_log['brewWaterProfile']);
$water_profiles = mysql_query($query_water_profiles, $brewing) or die(mysql_error());
$row_water_profiles = mysql_fetch_assoc($water_profiles);
$totalRows_water_profiles = mysql_num_rows($water_profiles);

$query_equip_profiles = sprintf("SELECT * FROM equip_profiles WHERE id='%s'", $row_log['brewEquipProfile']);
$equip_profiles = mysql_query($query_equip_profiles, $brewing) or die(mysql_error());
$row_equip_profiles = mysql_fetch_assoc($equip_profiles);
$totalRows_equip_profiles = mysql_num_rows($equip_profiles);

}

if ($source == "recipe") {
mysql_select_db($database_brewing, $brewing);
$query_log = sprintf("SELECT * FROM recipes WHERE id = '%s'", $colname_log);
$log = mysql_query($query_log, $brewing) or die(mysql_error());
$row_log = mysql_fetch_assoc($log);
$totalRows_log = mysql_num_rows($log);
}

mysql_select_db($database_brewing, $brewing);
$query_name = "SELECT * FROM brewer";
$name = mysql_query($query_name, $brewing) or die(mysql_error());
$row_name = mysql_fetch_assoc($name);
$totalRows_name = mysql_num_rows($name);


$colname_style = "1";
if (isset($_GET['brewStyle'])) {
  $colname_style = (get_magic_quotes_gpc()) ? $_GET['brewStyle'] : addslashes($_GET['brewStyle']);
}
mysql_select_db($database_brewing, $brewing);
$query_style = sprintf("SELECT * FROM styles WHERE brewStyle = '%s'", $colname_style);
$style = mysql_query($query_style, $brewing) or die(mysql_error());
$row_style = mysql_fetch_assoc($style);
$totalRows_style = mysql_num_rows($style);

if ($row_log['brewYeastProfile'] != "") {
mysql_select_db($database_brewing, $brewing);
$query_yeast_profiles = sprintf("SELECT * FROM yeast_profiles WHERE id='%s'", $row_log['brewYeastProfile']);
$yeast_profiles = mysql_query($query_yeast_profiles, $brewing) or die(mysql_error());
$row_yeast_profiles = mysql_fetch_assoc($yeast_profiles);
}

// Begin Beer XML output
$xml_output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; 
$xml_output .= "<!-- BeerXML Format Generated by BrewBlogger, browser-based brew log and calculation software, http://www.brewblogger.net -->\n";
// Begin <RECIPES> tag (contains all information)
$xml_output .= "<RECIPES>\n";
// Begin <RECIPE> tag (contains recipe information)
	$xml_output .= "\t<RECIPE>\n"; 
		// Recipe Information
		// Escaping illegal characters 
        $replaced = strtr($row_log['brewName'],$html_remove);
    	$xml_output .= "\t\t<NAME>" . $replaced . "</NAME>\n"; 
		$xml_output .= "\t\t<VERSION>1</VERSION>\n";
		$xml_output .= "\t\t<TYPE>" . $row_log['brewMethod'] . "</TYPE>\n"; 
		// Brewer Information 
		// Escaping illegal characters 
        $replaced = strtr($row_name['brewerFirstName'],$html_remove);
		$replaced2 = strtr($row_name['brewerLastName'],$html_remove);
		$xml_output .= "\t\t<BREWER>" . $replaced ." ".  $replaced2 . "</BREWER>\n"; 
		if ($row_pref['measFluid2'] == "gallons") { $xml_output .= "\t\t<BATCH_SIZE>" . round(($row_log['brewYield'] * 3.785), 3) . "</BATCH_SIZE>\n"; } else { $xml_output .= "\t\t<BATCH_SIZE>" . $row_log['brewYield'] . "</BATCH_SIZE>\n";  }
		$xml_output .= "\t\t<BOIL_SIZE></BOIL_SIZE>\n";
		$xml_output .= "\t\t<BOIL_TIME>".$row_log['brewBoilTime']."</BOIL_TIME>\n";
		// Begin <NOTES> and associated fermentation tags
		if ($source == "brewLog") {
		$replaced = strtr($row_log['brewInfo'],$string);
		$xml_output .= "\t\t<NOTES>" . $replaced . "</NOTES>\n";
		$xml_output .= "\t\t<EFFICIENCY>" . $row_log['brewEfficiency'] .  "</EFFICIENCY>\n";
		}	
		if ($source == "recipe") {
		$replaced = strtr($row_log['brewNotes'],$string);
		$xml_output .= "\t\t<NOTES>" . $replaced . "</NOTES>\n";
		}		
		// Begin <STYLE> tag (contains all associate beer style information)
		$xml_output .= "\t\t<STYLE>\n";
			// Escaping illegal characters 
        	$replaced = strtr($row_log['brewStyle'],$html_remove);
			$xml_output .= "\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t<VERSION>1</VERSION>\n";
			// Convert Style category number to Beer XML specifications
			if ($row_style['brewStyleGroup'] == "01") { $xml_output .= "\t\t\t<CATEGORY>" . "Light Lager" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "02") { $xml_output .= "\t\t\t<CATEGORY>" . "Pilsner" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "03") { $xml_output .= "\t\t\t<CATEGORY>" . "European Amber Lager" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "04") { $xml_output .= "\t\t\t<CATEGORY>" . "Dark Lager" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "05") { $xml_output .= "\t\t\t<CATEGORY>" . "Bock" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "06") { $xml_output .= "\t\t\t<CATEGORY>" . "Light Hybrid Beer" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "07") { $xml_output .= "\t\t\t<CATEGORY>" . "Amber Hybrid Beer" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "08") { $xml_output .= "\t\t\t<CATEGORY>" . "English Pale Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "09") { $xml_output .= "\t\t\t<CATEGORY>" . "Scottish and Irish Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "10") { $xml_output .= "\t\t\t<CATEGORY>" . "American Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "11") { $xml_output .= "\t\t\t<CATEGORY>" . "English Brown Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "12") { $xml_output .= "\t\t\t<CATEGORY>" . "Porter" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "13") { $xml_output .= "\t\t\t<CATEGORY>" . "Stout" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "14") { $xml_output .= "\t\t\t<CATEGORY>" . "India Pale Ale (IPA)" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "15") { $xml_output .= "\t\t\t<CATEGORY>" . "German Wheat and Rye Beer" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "16") { $xml_output .= "\t\t\t<CATEGORY>" . "Belgian and French Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "17") { $xml_output .= "\t\t\t<CATEGORY>" . "Sour Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "18") { $xml_output .= "\t\t\t<CATEGORY>" . "Belgian Strong Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "19") { $xml_output .= "\t\t\t<CATEGORY>" . "Strong Ale" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "20") { $xml_output .= "\t\t\t<CATEGORY>" . "Gruit Beer" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "21") { $xml_output .= "\t\t\t<CATEGORY>" . "Spice/Herb/Vegetable Beer" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "22") { $xml_output .= "\t\t\t<CATEGORY>" . "Smoke-Flavored and Wood-Aged Beer" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "23") { $xml_output .= "\t\t\t<CATEGORY>" . "Specialty Beer" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "24") { $xml_output .= "\t\t\t<CATEGORY>" . "Traditional Mead" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "25") { $xml_output .= "\t\t\t<CATEGORY>" . "Melomel (Fruit Mead)" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "26") { $xml_output .= "\t\t\t<CATEGORY>" . "Other Mead" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "27") { $xml_output .= "\t\t\t<CATEGORY>" . "Standard Cider and Perry" . "</CATEGORY>\n"; }
			if ($row_style['brewStyleGroup'] == "28") { $xml_output .= "\t\t\t<CATEGORY>" . "Specialty Cider and Perry" . "</CATEGORY>\n"; }
			$xml_output .= "\t\t\t<CATEGORY_NUMBER>" . $row_style['brewStyleGroup'] . "</CATEGORY_NUMBER>\n"; 
			$xml_output .= "\t\t\t<STYLE_LETTER>" . $row_style['brewStyleNum'] . "</STYLE_LETTER>\n";
			$xml_output .= "\t\t\t<STYLE_GUIDE>" . "BJCP" . "</STYLE_GUIDE>\n";
			// Convert Style category number to Beer XML specifications
			if ($row_style['brewStyleGroup'] == "01") { $xml_output .= "\t\t\t<TYPE>" . "Lager" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "02") { $xml_output .= "\t\t\t<TYPE>" . "Lager" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "03") { $xml_output .= "\t\t\t<TYPE>" . "Lager" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "04") { $xml_output .= "\t\t\t<TYPE>" . "Lager" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "05") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "06") { $xml_output .= "\t\t\t<TYPE>" . "Mixed" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "07") { $xml_output .= "\t\t\t<TYPE>" . "Mixed" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "08") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "09") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "10") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "11") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "12") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "13") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "14") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "15") { $xml_output .= "\t\t\t<TYPE>" . "Wheat" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "16") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "17") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "18") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "19") { $xml_output .= "\t\t\t<TYPE>" . "Ale" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "20") { $xml_output .= "\t\t\t<TYPE>" . "Mixed" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "21") { $xml_output .= "\t\t\t<TYPE>" . "Mixed" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "22") { $xml_output .= "\t\t\t<TYPE>" . "Mixed" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "23") { $xml_output .= "\t\t\t<TYPE>" . "Mixed" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "24") { $xml_output .= "\t\t\t<TYPE>" . "Mead" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "25") { $xml_output .= "\t\t\t<TYPE>" . "Mead" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "26") { $xml_output .= "\t\t\t<TYPE>" . "Mead" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "27") { $xml_output .= "\t\t\t<TYPE>" . "Cider" . "</TYPE>\n"; }
			if ($row_style['brewStyleGroup'] == "28") { $xml_output .= "\t\t\t<TYPE>" . "Cider" . "</TYPE>\n"; }
			// Style Specifics
			if ($row_style['brewStyleOG'] == "") { $xml_output .= "\t\t\t<OG_MIN>" . "Varies" . "</OG_MIN>\n"; }
			if ($row_style['brewStyleOG'] != "") { $xml_output .= "\t\t\t<OG_MIN>" . $row_style['brewStyleOG'] . "</OG_MIN>\n"; }
			if ($row_style['brewStyleOG'] == "") { $xml_output .= "\t\t\t<OG_MAX>" . "Varies" . "</OG_MAX>\n"; }
			if ($row_style['brewStyleOG'] != "") { $xml_output .= "\t\t\t<OG_MAX>" . $row_style['brewStyleOGMax'] . "</OG_MAX>\n"; }
			if ($row_style['brewStyleFG'] == "") { $xml_output .= "\t\t\t<FG_MIN>" . "Varies" . "</FG_MIN>\n"; }
			if ($row_style['brewStyleFG'] != "") { $xml_output .= "\t\t\t<FG_MIN>" . $row_style['brewStyleFGMax'] . "</FG_MIN>\n"; }
			if ($row_style['brewStyleFG'] == "") {$xml_output .= "\t\t\t<FG_MAX>" . "Varies" . "</FG_MAX>\n"; }
			if ($row_style['brewStyleFG'] != "") {$xml_output .= "\t\t\t<FG_MAX>" . $row_style['brewStyleFG'] . "</FG_MAX>\n"; }
			if ($row_style['brewStyleIBU'] == "") { $xml_output .= "\t\t\t<IBU_MIN>" . "Varies" . "</IBU_MIN>\n"; }
			if ($row_style['brewStyleIBU'] != "") { $xml_output .= "\t\t\t<IBU_MIN>" . $row_style['brewStyleIBU'] . "</IBU_MIN>\n"; }
			if ($row_style['brewStyleIBU'] == "") { $xml_output .= "\t\t\t<IBU_MAX>" . "Varies" . "</IBU_MAX>\n"; }
			if ($row_style['brewStyleIBU'] != "") { $xml_output .= "\t\t\t<IBU_MAX>" . $row_style['brewStyleIBUMax'] . "</IBU_MAX>\n"; }
			if ($row_style['brewStyleSRM'] == "") { $xml_output .= "\t\t\t<COLOR_MIN>" . "Varies" . "</COLOR_MIN>\n"; }
			if ($row_style['brewStyleSRM'] != "") { $xml_output .= "\t\t\t<COLOR_MIN>" . $row_style['brewStyleSRM'] . "</COLOR_MIN>\n"; }
			if ($row_style['brewStyleSRM'] == "") { $xml_output .= "\t\t\t<COLOR_MAX>" . "Varies" . "</COLOR_MAX>\n"; }
			if ($row_style['brewStyleSRM'] != "") { $xml_output .= "\t\t\t<COLOR_MAX>" . $row_style['brewStyleSRMMax'] . "</COLOR_MAX>\n"; }
			if ($row_style['brewStyleABV'] == "") { $xml_output .= "\t\t\t<ABV_MIN>" . "Varies" . "</ABV_MIN>\n"; }
			if ($row_style['brewStyleABV'] != "") { $xml_output .= "\t\t\t<ABV_MIN>" . $row_style['brewStyleABV'] . "</ABV_MIN>\n"; }
			if ($row_style['brewStyleABV'] == "") { $xml_output .= "\t\t\t<ABV_MAX>" . "Varies" . "</ABV_MAX>\n"; }
			if ($row_style['brewStyleABV'] != "") { $xml_output .= "\t\t\t<ABV_MAX>" . $row_style['brewStyleABVMax'] . "</ABV_MAX>\n"; }
		$xml_output .= "\t\t</STYLE>\n";
		
		
		// Begin <EQUIPMENT> tag
		if (($source == "brewLog") && ($row_log['brewEquipProfile'] != "")) { 
			$xml_output .= "\t\t<EQUIPMENT>\n";
			$replaced = strtr($row_equip_profiles['equipProfileName'],$html_remove);
			$xml_output .= "\t\t\t<NAME>".$replaced."</NAME>\n";
			$xml_output .= "\t\t\t<VERSION>1</VERSION>\n";
			if ($row_pref['measWeight2'] == "pounds") {
			$xml_output .= "\t\t\t<BOIL_SIZE>".weightconvert($row_equip_profiles['equipBoilVolume'], "kilograms")."</BOIL_SIZE>\n";
			$xml_output .= "\t\t\t<BATCH_SIZE>".weightconvert($row_equip_profiles['equipBatchSize'], "kilograms")."</BATCH_SIZE>\n";
			$xml_output .= "\t\t\t<TUN_VOLUME>".weightconvert($row_equip_profiles['equipMashTunVolume'], "kilograms")."</TUN_VOLUME>\n";
			$xml_output .= "\t\t\t<TUN_WEIGHT>".weightconvert($row_equip_profiles['equipMashTunWeight'], "kilograms")."</TUN_WEIGHT>\n";
			$xml_output .= "\t\t\t<TOP_UP_WATER>".weightconvert($row_equip_profiles['equipTopUp'], "kilograms")."</TOP_UP_WATER>\n";
			$xml_output .= "\t\t\t<LAUTER_DEADSPACE>".weightconvert($row_equip_profiles['equipMashTunDeadspace'], "kilograms")."</LAUTER_DEADSPACE>\n";
			$xml_output .= "\t\t\t<TOP_UP_KETTLE>".weightconvert($row_equip_profiles['equipTopUpKettle'], "kilograms")."</TOP_UP_KETTLE>\n";
			$xml_output .= "\t\t\t<TRUB_CHILLER_LOSS>".weightconvert($row_equip_profiles['equipLoss'], "kilograms")."</TRUB_CHILLER_LOSS>\n";
			} else {
			$xml_output .= "\t\t\t<BOIL_SIZE>".$row_equip_profiles['equipBoilVolume']."</BOIL_SIZE>\n";
			$xml_output .= "\t\t\t<BATCH_SIZE>".$row_equip_profiles['equipBatchSize']."</BATCH_SIZE>\n";
			$xml_output .= "\t\t\t<TUN_VOLUME>".$row_equip_profiles['equipMashTunVolume']."</TUN_VOLUME>\n";
			$xml_output .= "\t\t\t<TUN_WEIGHT>".$row_equip_profiles['equipMashTunWeight']."</TUN_WEIGHT>\n";
			$xml_output .= "\t\t\t<TOP_UP_WATER>".$row_equip_profiles['equipTopUp']."</TOP_UP_WATER>\n";
			$xml_output .= "\t\t\t<LAUTER_DEADSPACE>".$row_equip_profiles['equipMashTunDeadspace']."</LAUTER_DEADSPACE>\n";
			$xml_output .= "\t\t\t<TOP_UP_KETTLE>".$row_equip_profiles['equipTopUpKettle']."</TOP_UP_KETTLE>\n";
			$xml_output .= "\t\t\t<TRUB_CHILLER_LOSS>".$row_equip_profiles['equipLoss']."</TRUB_CHILLER_LOSS>\n";
			}
			$xml_output .= "\t\t\t<TUN_SPECIFIC_HEAT>".$row_equip_profiles['equipMashTunSpecificHeat']."</TUN_SPECIFIC_HEAT>\n";
			$xml_output .= "\t\t\t<EVAP_RATE>".$row_equip_profiles['equipEvapRate']."</EVAP_RATE>\n";
			$xml_output .= "\t\t\t<BOIL_TIME>".$row_log['brewBoilTime']."</BOIL_TIME>\n";
			$xml_output .= "\t\t\t<HOP_UTILIZATION>".$row_equip_profiles['equipHopUtil']."</HOP_UTILIZATION>\n";
			$replaced = strtr($row_equip_profiles['equipNotes'],$string);
			$xml_output .= "\t\t\t<NOTES>".$replaced."</NOTES>\n";
			$xml_output .= "\t\t</EQUIPMENT>\n";
		}
		// Begin <HOPS> tag (contains all Hop information)
		$xml_output .= "\t\t<HOPS>\n";
			if ($row_log['brewHops1'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
				// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops1'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops1IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops1Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops1Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops1Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops1Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops1Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops1Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n";
			}
			if ($row_log['brewHops2'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops2'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops2IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops2Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops2Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops2Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops2Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops2Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops2Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops2Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
			if ($row_log['brewHops3'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops3'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops3IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops3Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops3Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops3Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops3Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops3Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops3Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops3Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
			if ($row_log['brewHops4'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops4'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops4IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops4Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops4Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops4Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops4Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops4Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops4Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops4Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
			if ($row_log['brewHops5'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops5'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops5IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops5Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops5Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops5Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops5Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops5Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops5Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops5Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
			if ($row_log['brewHops6'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops6'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops6IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops6Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops6Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops6Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops6Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops6Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops6Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops6Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
			if ($row_log['brewHops7'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops7'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops7IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops7Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops7Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops7Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops7Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops7Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops7Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops7Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
			if ($row_log['brewHops8'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops8'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";;
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops8IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops8Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops8Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops8Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops8Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops8Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops8Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops8Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
			if ($row_log['brewHops9'] !="") {
			$xml_output .= "\t\t\t<HOP>\n";
			// Escaping illegal characters 
        		$replaced = strtr($row_log['brewHops9'],$html_remove);
				$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
				$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
				$xml_output .= "\t\t\t\t<ALPHA>" . $row_log['brewHops9IBU'] . "</ALPHA>\n";
				if ($row_pref['measWeight1'] == "ounces") { // BeerXML standard is kilograms
				$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewHops0Weight'] * 0.028349), 6)."</AMOUNT>\n";
				} else { 
				$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewHops0Weight']."</AMOUNT>\n";
				}
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops9Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<USE>" . $row_log['brewHops9Use'] . "</USE>\n";
				$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewHops9Time'] . "</TIME>\n";
				$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewHops9Type'] . "</TYPE>\n";
				$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewHops9Form'] . "</FORM>\n";
			$xml_output .= "\t\t\t</HOP>\n"; 
			}
		$xml_output .= "\t\t</HOPS>\n";
		$xml_output .= "\t\t<FERMENTABLES>\n";
		// Begin <FERMENTABLES> tags for extracts
		if ($row_log['brewExtract1'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewExtract1'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Extract" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewExtract1Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewExtract1Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewExtract2'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewExtract2'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Extract" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewExtract2Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewExtract2Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewExtract3'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewExtract3'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Extract" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewExtract3Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewExtract3Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewExtract4'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewExtract4'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Extract" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewExtract4Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewExtract4Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewExtract5'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewExtract5'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Extract" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewExtract5Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewExtract5Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		
		// Begin <FERMENTABLES> tags for grains
		if ($row_log['brewGrain1'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain1'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain1Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain1Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain2'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain2'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain2Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain2Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain3'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain3'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain3Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain3Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain4'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain4'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain4Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain4Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain5'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain5'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain5Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain5Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain6'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain6'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain6Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain6Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain7'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain7'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain7Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain7Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain8'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain8'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain8Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain8Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewGrain9'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewGrain8'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Grain" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewGrain9Weight'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewGrain9Weight']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		// Begin <FERMENTABLES> tags for adjuncts
		if ($row_log['brewAddition1'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition1'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Adjunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition1Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition1Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition2'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition2'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Adjunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition2Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition2Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition3'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition3'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Adjunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition3Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition3Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition4'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition4'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Adjunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition4Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition4Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition5'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition5'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Adjunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition5Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition5Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition6'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition6'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Adjunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition6Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition6Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition7'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition7'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Ajunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition7Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition7Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition8'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition8'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Ajunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition8Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition8Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		if ($row_log['brewAddition9'] !="") {
		$xml_output .= "\t\t\t<FERMENTABLE>\n";
			$replaced = strtr($row_log['brewAddition9'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . "Ajunct" . "</TYPE>\n";
			if ($row_pref['measWeight2'] == "pounds") { // BeerXML standard is kilograms
			$xml_output .= "\t\t\t\t<AMOUNT>" . round(($row_log['brewAddition9Amt'] * 0.4535), 2)."</AMOUNT>\n";
			} else {
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewAddition9Amt']."</AMOUNT>\n";
			}
		$xml_output .= "\t\t\t</FERMENTABLE>\n";
		}
		$xml_output .= "\t\t</FERMENTABLES>\n";
		// Begin <YEASTS> tag
		
		if ($row_log['brewYeastProfile'] == "") {
		$xml_output .= "\t\t<YEASTS>\n";
		$xml_output .= "\t\t\t<YEAST>\n";
			$replaced = strtr($row_log['brewYeast'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewYeastType'] . "</TYPE>\n";
			$xml_output .= "\t\t\t\t<FORM>" . $row_log['brewYeastForm'] . "</FORM>\n";
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewYeastAmount'] . "</AMOUNT>\n";
			$xml_output .= "\t\t\t\t<LABORATORY>" . $row_log['brewYeastMan'] . "</LABORATORY>\n";
		$xml_output .= "\t\t\t</YEAST>\n";
		$xml_output .= "\t\t</YEASTS>\n";
		}
		if ($row_log['brewYeastProfile'] != "") {
		$xml_output .= "\t\t<YEASTS>\n";
		$xml_output .= "\t\t\t<YEAST>\n";
			$replaced = strtr($row_yeast_profiles['yeastName'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . $row_yeast_profiles['yeastType'] . "</TYPE>\n";
			$xml_output .= "\t\t\t\t<FORM>" . $row_yeast_profiles['yeastForm']. "</FORM>\n";
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewYeastAmount'] . "</AMOUNT>\n";
			$xml_output .= "\t\t\t\t<LABORATORY>" . $row_yeast_profiles['yeastLab'] . "</LABORATORY>\n";
			$xml_output .= "\t\t\t\t<PRODUCT_ID>" . $row_yeast_profiles['yeastProdID'] . "</PRODUCT_ID>\n";
			if ($row_pref['measTemp'] == "F") {

			$xml_output .= "\t\t\t\t<MIN_TEMPERATURE>" . tempconvert($row_yeast_profiles['yeastMinTemp'], "C") . "</MIN_TEMPERATURE>\n";
			$xml_output .= "\t\t\t\t<MAX_TEMPERATURE>" . tempconvert($row_yeast_profiles['yeastMaxTemp'], "C") . "</MAX_TEMPERATURE>\n";
			} else {
			$xml_output .= "\t\t\t\t<MIN_TEMPERATURE>" . $row_yeast_profiles['yeastMinTemp'] . "</MIN_TEMPERATURE>\n";
			$xml_output .= "\t\t\t\t<MAX_TEMPERATURE>" . $row_yeast_profiles['yeastMaxTemp'] . "</MAX_TEMPERATURE>\n";
			}
			$xml_output .= "\t\t\t\t<FLOCCULATION>" . $row_yeast_profiles['yeastFloc'] . "</FLOCCULATION>\n";
			$xml_output .= "\t\t\t\t<ATTENUATION>" . $row_yeast_profiles['yeastAtten'] . "</ATTENUATION>\n";
			$xml_output .= "\t\t\t\t<BEST_FOR>" . $row_yeast_profiles['yeastBestFor'] . "</BEST_FOR>\n";
			$xml_output .= "\t\t\t\t<MAX_REUSE>" . $row_yeast_profiles['yeastMaxReuse'] . "</MAX_REUSE>\n";
			$replaced = strtr($row_yeast_profiles['yeastNotes'],$string);
			$xml_output .= "\t\t\t\t<NOTES>" . $replaced . "</NOTES>\n";
		$xml_output .= "\t\t\t</YEAST>\n";
		$xml_output .= "\t\t</YEASTS>\n";
		}
		// Begin <MISCS> tags for non-fermentables
		$xml_output .= "\t\t<MISCS>\n";
		if ($row_log['brewMisc1Name'] !="") { 
		$xml_output .= "\t\t\t<MISC>\n";
			$xml_output .= "\t\t\t\t<NAME>" . $row_log['brewMisc1Name'] . "</NAME>\n";
			$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewMisc1Type'] . "</TYPE>\n";
			$xml_output .= "\t\t\t\t<USE>" . $row_log['brewMisc1Use'] . "</USE>\n";
			$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewMisc1Time'] . "</TIME>\n";
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewMisc1Amount'] . "</AMOUNT>\n";
		$xml_output .= "\t\t\t</MISC>\n";
		}
		if ($row_log['brewMisc2Name'] !="") { 
		$xml_output .= "\t\t\t<MISC>\n";
			$xml_output .= "\t\t\t\t<NAME>" . $row_log['brewMisc2Name'] . "</NAME>\n";
			$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewMisc2Type'] . "</TYPE>\n";
			$xml_output .= "\t\t\t\t<USE>" . $row_log['brewMisc2Use'] . "</USE>\n";
			$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewMisc2Time'] . "</TIME>\n";
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewMisc2Amount'] . "</AMOUNT>\n";
		$xml_output .= "\t\t\t</MISC>\n";
		}
		if ($row_log['brewMisc3Name'] !="") { 
		$xml_output .= "\t\t\t<MISC>\n";
			$xml_output .= "\t\t\t\t<NAME>" . $row_log['brewMisc3Name'] . "</NAME>\n";
			$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewMisc3Type'] . "</TYPE>\n";
			$xml_output .= "\t\t\t\t<USE>" . $row_log['brewMisc3Use'] . "</USE>\n";
			$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewMisc3Time'] . "</TIME>\n";
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewMisc3Amount'] . "</AMOUNT>\n";
		$xml_output .= "\t\t\t</MISC>\n";
		}
		if ($row_log['brewMisc4Name'] !="") { 
		$xml_output .= "\t\t\t<MISC>\n";
			$xml_output .= "\t\t\t\t<NAME>" . $row_log['brewMisc4Name'] . "</NAME>\n";
			$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
			$xml_output .= "\t\t\t\t<TYPE>" . $row_log['brewMisc4Type'] . "</TYPE>\n";
			$xml_output .= "\t\t\t\t<USE>" . $row_log['brewMisc4Use'] . "</USE>\n";
			$xml_output .= "\t\t\t\t<TIME>" . $row_log['brewMisc4Time'] . "</TIME>\n";
			$xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewMisc4Amount'] . "</AMOUNT>\n";
		$xml_output .= "\t\t\t</MISC>\n";
		}
		$xml_output .= "\t\t</MISCS>\n";
		
		// Begin <WATERS> tag (contains all water information)
		
		if (($source == "brewLog") && ($row_log['brewWaterProfile'] == "")) { 
		$xml_output .= "\t\t<WATERS>\n";
		$xml_output .= "\t\t\t<WATER>\n";
			$replaced = strtr($row_log['brewWaterName'],$html_remove);
			$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
			$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
			if ($row_log['brewWaterAmount'] == "" ) { $xml_output .= "\t\t\t\t<AMOUNT></AMOUNT>\n"; }
			if ($row_log['brewWaterAmount'] != "" ) { $xml_output .= "\t\t\t\t<AMOUNT>" . $row_log['brewWaterAmount'] . "</AMOUNT>\n"; }
			if ($row_log['brewWaterCalcium'] == "" ) { $xml_output .= "\t\t\t\t<CALCIUM></CALCIUM>\n"; }
			if ($row_log['brewWaterCalcium'] != "" ) { $xml_output .= "\t\t\t\t<CALCIUM>" . $row_log['brewWaterCalcium'] . "</CALCIUM>\n"; }
			if ($row_log['brewWaterBicarb'] == "" ) { $xml_output .= "\t\t\t\t<BICARBONATE></BICARBONATE>\n"; }
			if ($row_log['brewWaterBicarb'] != "" ) { $xml_output .= "\t\t\t\t<BICARBONATE>" . $row_log['brewWaterBicarb'] . "</BICARBONATE>\n"; }
			if ($row_log['brewWaterSulfate'] == "" ) { $xml_output .= "\t\t\t\t<SULFATE></SULFATE>\n"; }
			if ($row_log['brewWaterSulfate'] != "" ) { $xml_output .= "\t\t\t\t<SULFATE>" . $row_log['brewWaterSulfate'] . "</SULFATE>\n"; }
			if ($row_log['brewWaterChloride'] == "" ) { $xml_output .= "\t\t\t\t<CHLORIDE></CHLORIDE>\n"; }
			if ($row_log['brewWaterChloride'] != "" ) { $xml_output .= "\t\t\t\t<CHLORIDE>" . $row_log['brewWaterChloride'] . "</CHLORIDE>\n"; }
			if ($row_log['brewWaterSodium'] == "" ) { $xml_output .= "\t\t\t\t<SODIUM></SODIUM>\n"; }
			if ($row_log['brewWaterSodium'] != "" ) { $xml_output .= "\t\t\t\t<SODIUM>" . $row_log['brewWaterSodium'] . "</SODIUM>\n"; }
			if ($row_log['brewWaterMagnesium'] == "" ) { $xml_output .= "\t\t\t\t<MAGNESIUM></MAGNESIUM>\n"; }
			if ($row_log['brewWaterMagnesium'] != "" ) { $xml_output .= "\t\t\t\t<MAGNESIUM>" . $row_log['brewWaterMagnesium'] . "</MAGNESIUM>\n"; }
			if ($row_log['brewWaterAmount'] == "" ) { $xml_output .= "\t\t\t\t<PH>" . $row_log['brewWaterPH'] . "</PH>\n"; }
			if ($row_log['brewWaterNotes'] == "" ) { $xml_output .= "\t\t\t\t<NOTES></NOTES>\n"; }
			if ($row_log['brewWaterNotes'] != "" ) { $xml_output .= "\t\t\t\t<NOTES>" . $row_log['brewWaterNotes'] . "</NOTES>\n"; }
		$xml_output .= "\t\t\t</WATER>\n";
		$xml_output .= "\t\t</WATERS>\n";
		}
		
		if (($source == "brewLog") && ($row_log['brewWaterProfile'] != "")) { 
		$xml_output .= "\t\t<WATERS>\n";
		$xml_output .= "\t\t\t<WATER>\n";
		$replaced = strtr($row_water_profiles['waterName'],$html_remove);
		$xml_output .= "\t\t\t\t<NAME>" . $replaced . "</NAME>\n";
		$xml_output .= "\t\t\t\t<VERSION>1</VERSION>\n";
		$xml_output .= "\t\t\t\t<AMOUNT>" . $row_water_profiles['waterAmount'] . "</AMOUNT>\n"; 
		$xml_output .= "\t\t\t\t<CALCIUM>" . $row_water_profiles['waterCalcium'] . "</CALCIUM>\n";
		$xml_output .= "\t\t\t\t<BICARBONATE>" . $row_water_profiles['waterBicarbonate'] . "</BICARBONATE>\n";
		$xml_output .= "\t\t\t\t<SULFATE>" . $row_water_profiles['waterSulfate'] . "</SULFATE>\n";
		$xml_output .= "\t\t\t\t<CHLORIDE>" . $row_water_profiles['waterChloride'] . "</CHLORIDE>\n";
		$xml_output .= "\t\t\t\t<SODIUM>" . $row_water_profiles['waterSodium'] . "</SODIUM>\n";
		$xml_output .= "\t\t\t\t<MAGNESIUM>" . $row_water_profiles['waterMagnesium'] . "</MAGNESIUM>\n";
		$xml_output .= "\t\t\t\t<PH>" . $row_water_profiles['waterPH'] . "</PH>\n";
		$replaced = strtr($row_water_profiles['waterNotes'],$string);
		$xml_output .= "\t\t\t\t<NOTES>" . $replaced . "</NOTES>\n"; 
		$xml_output .= "\t\t\t</WATER>\n";
		$xml_output .= "\t\t</WATERS>\n";
		}
		
		// Begin <MASH> tag (contains all mash information)
		if (($source == "brewLog") && ($row_log['brewMashProfile'] == "")) { 
		$xml_output .= "\t\t<MASH>\n";
			$xml_output .= "\t\t\t<NAME>" . $row_log['brewMashType'] . "</NAME>\n";
			$xml_output .= "\t\t\t<VERSION>1</VERSION>\n";
			if (($row_pref['measTemp'] == "F") && ($row_log['brewMashGrainTemp'] != ""))  { $xml_output .= "\t\t\t<GRAIN_TEMP>" . tempconvert($row_log['brewMashGrainTemp'], "C") . "</GRAIN_TEMP>\n";  } 
			elseif (($row_pref['measTemp'] == "C") && ($row_log['brewMashGrainTemp'] != "")) { $xml_output .= "\t\t\t<GRAIN_TEMP>" . $row_log['brewMashGrainTemp'] . "</GRAIN_TEMP>\n";	}
			else { $xml_output .= "\t\t\t<GRAIN_TEMP></GRAIN_TEMP>\n"; }		
				$xml_output .= "\t\t\t\t<MASH_STEPS>\n";
				if ($row_log['brewMashStep1Name'] != "") {
				$xml_output .= "\t\t\t\t\t<MASH_STEP>\n";
					$xml_output .= "\t\t\t\t\t\t<NAME>" . $row_log['brewMashStep1Name'] . "</NAME>\n";
					$xml_output .= "\t\t\t\t\t\t<VERSION>1</VERSION>\n";
					$xml_output .= "\t\t\t\t\t\t<TYPE>" . $row_log['brewMashStep1Desc'] . "</TYPE>\n";
					if (($row_pref['measTemp'] == "F") && ($row_log['brewMashStep1Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . tempconvert($row_log['brewMashStep1Temp'], "C") . "</STEP_TEMP>\n"; } 
					elseif (($row_pref['measTemp'] == "C") && ($row_log['brewMashStep1Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . $row_log['brewMashStep1Temp'] . "</STEP_TEMP>\n"; }
					else { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP></STEP_TEMP>\n"; }
					$xml_output .= "\t\t\t\t\t\t<STEP_TIME>" . $row_log['brewMashStep1Time'] . "</STEP_TIME>\n";
				$xml_output .= "\t\t\t\t\t</MASH_STEP>\n";
				}
				if ($row_log['brewMashStep2Name'] != "") {
				$xml_output .= "\t\t\t\t\t<MASH_STEP>\n";
					$xml_output .= "\t\t\t\t\t\t<NAME>" . $row_log['brewMashStep2Name'] . "</NAME>\n";
					$xml_output .= "\t\t\t\t\t\t<VERSION>1</VERSION>\n";
					$xml_output .= "\t\t\t\t\t\t<TYPE>" . $row_log['brewMashStep2Desc'] . "</TYPE>\n";
					if (($row_pref['measTemp'] == "F") && ($row_log['brewMashStep2Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . tempconvert($row_log['brewMashStep2Temp'], "C") . "</STEP_TEMP>\n"; } 
					elseif (($row_pref['measTemp'] == "C") && ($row_log['brewMashStep2Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . $row_log['brewMashStep2Temp'] . "</STEP_TEMP>\n"; }
					else { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP></STEP_TEMP>\n"; }
					$xml_output .= "\t\t\t\t\t\t<STEP_TIME>" . $row_log['brewMashStep2Time'] . "</STEP_TIME>\n";
				$xml_output .= "\t\t\t\t\t</MASH_STEP>\n";
				}
				if ($row_log['brewMashStep3Name'] != "") {
				$xml_output .= "\t\t\t\t\t<MASH_STEP>\n";
					$xml_output .= "\t\t\t\t\t\t<NAME>" . $row_log['brewMashStep3Name'] . "</NAME>\n";
					$xml_output .= "\t\t\t\t\t\t<VERSION>1</VERSION>\n";
					$xml_output .= "\t\t\t\t\t\t<TYPE>" . $row_log['brewMashStep3Desc'] . "</TYPE>\n";
					if (($row_pref['measTemp'] == "F") && ($row_log['brewMashStep3Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . tempconvert($row_log['brewMashStep3Temp'], "C") . "</STEP_TEMP>\n"; } 
					elseif (($row_pref['measTemp'] == "C") && ($row_log['brewMashStep3Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . $row_log['brewMashStep3Temp'] . "</STEP_TEMP>\n"; }
					else { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP></STEP_TEMP>\n"; }
					$xml_output .= "\t\t\t\t\t\t<STEP_TIME>" . $row_log['brewMashStep3Time'] . "</STEP_TIME>\n";
				$xml_output .= "\t\t\t\t\t</MASH_STEP>\n";
				}
				if ($row_log['brewMashStep4Name'] != "") {
				$xml_output .= "\t\t\t\t\t<MASH_STEP>\n";
					$xml_output .= "\t\t\t\t\t\t<NAME>" . $row_log['brewMashStep4Name'] . "</NAME>\n";
					$xml_output .= "\t\t\t\t\t\t<VERSION>1</VERSION>\n";
					$xml_output .= "\t\t\t\t\t\t<TYPE>" . $row_log['brewMashStep4Desc'] . "</TYPE>\n";
					if (($row_pref['measTemp'] == "F") && ($row_log['brewMashStep4Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . tempconvert($row_log['brewMashStep4Temp'], "C") . "</STEP_TEMP>\n"; } 
					elseif (($row_pref['measTemp'] == "C") && ($row_log['brewMashStep4Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . $row_log['brewMashStep4Temp'] . "</STEP_TEMP>\n"; }
					else { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP></STEP_TEMP>\n"; }
					$xml_output .= "\t\t\t\t\t\t<STEP_TIME>" . $row_log['brewMashStep4Time'] . "</STEP_TIME>\n";
				$xml_output .= "\t\t\t\t\t</MASH_STEP>\n";
				}
				if ($row_log['brewMashStep5Name'] != "") {
				$xml_output .= "\t\t\t\t\t<MASH_STEP>\n";
					$xml_output .= "\t\t\t\t\t\t<NAME>" . $row_log['brewMashStep5Name'] . "</NAME>\n";
					$xml_output .= "\t\t\t\t\t\t<VERSION>1</VERSION>\n";
					$xml_output .= "\t\t\t\t\t\t<TYPE>" . $row_log['brewMashStep5Desc'] . "</TYPE>\n";
					if (($row_pref['measTemp'] == "F") && ($row_log['brewMashStep5Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . tempconvert($row_log['brewMashStep5Temp'], "C") . "</STEP_TEMP>\n"; } 
					elseif (($row_pref['measTemp'] == "C") && ($row_log['brewMashStep5Temp'] != "")) { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . $row_log['brewMashStep5Temp'] . "</STEP_TEMP>\n"; }
					else { $xml_output .= "\t\t\t\t\t\t<STEP_TEMP></STEP_TEMP>\n"; }
					$xml_output .= "\t\t\t\t\t\t<STEP_TIME>" . $row_log['brewMashStep5Time'] . "</STEP_TIME>\n";
				$xml_output .= "\t\t\t\t\t</MASH_STEP>\n";
				}
				$xml_output .= "\t\t\t\t</MASH_STEPS>\n";
			if ($row_log['brewMashTunTemp'] == "") { $xml_output .= "\t\t\t<TUN_TEMP></TUN_TEMP>\n"; }
			if ($row_log['brewMashTunTemp'] != "") { 
				if ($row_pref['measTemp'] == "F") { $xml_output .= "\t\t\t<TUN_TEMP>" . tempconvert($row_log['brewMashTunTemp'], "C") . "</TUN_TEMP>\n"; }
				else { $xml_output .= "\t\t\t<TUN_TEMP>" . $row_log['brewMashTunTemp'] . "</TUN_TEMP>\n"; }
			}
			if ($row_log['brewMashSpargeTemp'] == "") { $xml_output .= "\t\t\t<SPARGE_TEMP></SPARGE_TEMP>\n"; }
			if ($row_log['brewMashSpargeTemp'] != "") { 
				if ($row_pref['measTemp'] == "F") { $xml_output .= "\t\t\t<SPARGE_TEMP>" . tempconvert($row_log['brewMashSpargeTemp'], "C") . "</SPARGE_TEMP>\n"; }
				else { $xml_output .= "\t\t\t<SPARGE_TEMP>" . $row_log['brewMashSpargeTemp'] . "</SPARGE_TEMP>\n"; }
			}
			if ($row_log['brewMashPH'] == "") { $xml_output .= "\t\t\t<PH></PH>\n"; }
			if ($row_log['brewMashPH'] != "") { $xml_output .= "\t\t\t<PH>" . $row_log['brewMashPH'] . "</PH>\n"; }
			if ($row_log['brewMashEquipAdjust'] == "") { $xml_output .= "\t\t\t<EQUIP_ADJUST></EQUIP_ADJUST>\n"; }
			if ($row_log['brewMashEquipAdjust'] != "") { $xml_output .= "\t\t\t<EQUIP_ADJUST>" . $row_log['brewMashEquipAdjust'] . "</EQUIP_ADJUST>\n"; }
		$xml_output .= "\t\t</MASH>\n";
		}
		
		if (($source == "brewLog") && ($row_log['brewMashProfile'] != "")) { 
		$xml_output .= "\t\t<MASH>\n";
		$replaced = strtr($row_mash_profiles['mashProfileName'],$html_remove);
		$xml_output .= "\t\t\t<NAME>" . $replaced . "</NAME>\n";
		$xml_output .= "\t\t\t<VERSION>1</VERSION>\n";
		if (($row_pref['measTemp'] == "F") && ($row_mash_profiles['mashGrainTemp'] != "")) $xml_output .= "\t\t\t<GRAIN_TEMP>" . tempconvert($row_mash_profiles['mashGrainTemp'],"C") . "</GRAIN_TEMP>\n";
		else $xml_output .= "\t\t\t<GRAIN_TEMP>" . $row_mash_profiles['mashGrainTemp'] . "</GRAIN_TEMP>\n";
		if (($row_pref['measTemp'] == "F") && ($row_mash_profiles['mashTunTemp'] != "")) $xml_output .= "\t\t\t<TUN_TEMP>" . tempconvert($row_mash_profiles['mashTunTemp'], "C") . "</TUN_TEMP>\n";
		else $xml_output .= "\t\t\t<TUN_TEMP>" . $row_mash_profiles['mashTunTemp'] . "</TUN_TEMP>\n";
		if (($row_pref['measTemp'] == "F") && ($row_mash_profiles['mashSpargeTemp'] != "")) $xml_output .= "\t\t\t<SPARGE_TEMP>" . tempconvert($row_mash_profiles['mashSpargeTemp'], "C") . "</SPARGE_TEMP>\n";
		else $xml_output .= "\t\t\t<SPARGE_TEMP>" . $row_mash_profiles['mashSpargeTemp'] . "</SPARGE_TEMP>\n";
		$xml_output .= "\t\t\t<PH>" . $row_mash_profiles['mashPH'] . "</PH>\n";
		$xml_output .= "\t\t\t<EQUIP_ADJUST>" . $row_mash_profiles['mashEquipAdjust'] . "</EQUIP_ADJUST>\n";
		$xml_output .= "\t\t\t\t<MASH_STEPS>\n";
			do {
			$xml_output .= "\t\t\t\t\t<MASH_STEP>\n";
			$xml_output .= "\t\t\t\t\t\t<NAME>" . $row_mash_steps['stepName'] . "</NAME>\n";
			$xml_output .= "\t\t\t\t\t\t<VERSION>1</VERSION>\n";
			$xml_output .= "\t\t\t\t\t\t<TYPE>" . $row_mash_steps['stepType'] . "</TYPE>\n";
			if (($row_pref['measTemp'] == "F") && ($row_mash_steps['stepTemp'] != "")) $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . tempconvert($row_mash_steps['stepTemp'], "C") . "</STEP_TEMP>\n";
			else $xml_output .= "\t\t\t\t\t\t<STEP_TEMP>" . $row_mash_steps['stepTemp']. "</STEP_TEMP>\n";
			$xml_output .= "\t\t\t\t\t\t<STEP_TIME>" . $row_mash_steps['stepTime'] . "</STEP_TIME>\n";
			$xml_output .= "\t\t\t\t\t\t<RAMP_TIME>" . $row_mash_steps['stepTime'] . "</RAMP_TIME>\n";
			if (($row_pref['measTemp'] == "F") && ($row_mash_steps['stepEndTemp'] != "")) $xml_output .= "\t\t\t\t\t\t<END_TEMP>" . tempconvert($row_mash_steps['stepEndTemp'], "C") . "</END_TEMP>\n";
			else $xml_output .= "\t\t\t\t\t\t<END_TEMP>" . $row_mash_steps['stepEndTemp'] . "</END_TEMP>\n";
			if (($row_pref['measFluid2'] == "gallons") && ($row_mash_steps['stepInfuseAmt'] != "")) $xml_output .= "\t\t\t\t\t\t<INFUSE_AMT>" . volumeconvert($row_mash_steps['stepInfuseAmt'], "liters"). "</INFUSE_AMT>\n";
			else $xml_output .= "\t\t\t\t\t\t<INFUSE_AMT>" . $row_mash_steps['stepInfuseAmt'] . "</INFUSE_AMT>\n";
			$xml_output .= "\t\t\t\t\t</MASH_STEP>\n";
			} while ($row_mash_steps =  mysql_fetch_assoc($mash_steps));
		$xml_output .= "\t\t\t\t</MASH_STEPS>\n";
		$xml_output .= "\t\t</MASH>\n";
		}
		
		// Escaping illegal characters 
	    if ($source == "brewLog") $replaced = strtr($row_log['brewComments'],$string);
		$xml_output .= "\t\t<TASTE_NOTES>" . $replaced . "</TASTE_NOTES>\n";
		// Gravity information
		$xml_output .= "\t\t<OG>" . round($row_log['brewOG'], 3) . "</OG>\n";
		$xml_output .= "\t\t<FG>" . round($row_log['brewFG'], 3) . "</FG>\n";
		$xml_output .= "\t\t<EST_OG>" . round($row_log['brewOG'], 3) . "</EST_OG>\n";
		$xml_output .= "\t\t<EST_FG>" . round($row_log['brewFG'], 3) . "</EST_FG>\n";
		$xml_output .= "\t\t<DISPLAY_OG>" . round($row_log['brewOG'], 3) . "</DISPLAY_OG>\n";
		$xml_output .= "\t\t<DISPLAY_FG>" . round($row_log['brewFG'], 3) . "</DISPLAY_FG>\n";
		$xml_output .= "\t\t<PRIMARY_AGE>" . $row_log['brewPrimary'] . "</PRIMARY_AGE>\n";
		if (($row_pref['measTemp'] == "F") && ($row_log['brewPrimaryTemp'] != "")) { $xml_output .= "\t\t<PRIMARY_TEMP>" .  tempconvert($row_log['brewPrimaryTemp'], "C") . "</PRIMARY_TEMP>\n"; } 
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewPrimaryTemp'] != "")) { $xml_output .= "\t\t<PRIMARY_TEMP>" . $row_log['brewPrimaryTemp'] . "</PRIMARY_TEMP>\n";	}
		else { $xml_output .= "\t\t<PRIMARY_TEMP></PRIMARY_TEMP>\n"; }
		
		if (($row_pref['measTemp'] == "F") && ($row_log['brewPrimaryTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_PRIMARY_TEMP>" .  tempconvert($row_log['brewPrimaryTemp'], "C") . "</DISPLAY_PRIMARY_TEMP>\n"; } 
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewPrimaryTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_PRIMARY_TEMP>" . $row_log['brewPrimaryTemp'] . "</DISPLAY_PRIMARY_TEMP>\n";	}
		else { $xml_output .= "\t\t<DISPLAY_PRIMARY_TEMP></DISPLAY_PRIMARY_TEMP>\n"; }
		
		$xml_output .= "\t\t<SECONDARY_AGE>" . $row_log['brewSecondary'] . "</SECONDARY_AGE>\n";
		if (($row_pref['measTemp'] == "F") && ($row_log['brewSecondaryTemp'] != "")) { $xml_output .= "\t\t<SECONDARY_TEMP>" . tempconvert($row_log['brewSecondaryTemp'], "C") . "</SECONDARY_TEMP>\n"; }
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewSecondaryTemp'] != "")) { $xml_output .= "\t\t<SECONDARY_TEMP>" . $row_log['brewSecondaryTemp'] . "</SECONDARY_TEMP>\n"; }
		else { $xml_output .= "\t\t<SECONDARY_TEMP></SECONDARY_TEMP>\n"; }
		
		if (($row_pref['measTemp'] == "F") && ($row_log['brewSecondaryTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_SECONDARY_TEMP>" . tempconvert($row_log['brewSecondaryTemp'], "C") . "</DISPLAY_SECONDARY_TEMP>\n"; }
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewSecondaryTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_SECONDARY_TEMP>" . $row_log['brewSecondaryTemp'] . "</DISPLAY_SECONDARY_TEMP>\n"; }
		else { $xml_output .= "\t\t<DISPLAY_SECONDARY_TEMP></DISPLAY_SECONDARY_TEMP>\n"; }
		
		$xml_output .= "\t\t<TERTIARY_AGE>" . $row_log['brewTertiary'] . "</TERTIARY_AGE>\n";
		if (($row_pref['measTemp'] == "F") && ($row_log['brewTertiaryTemp'] != "")) { $xml_output .= "\t\t<TERTIARY_TEMP>" . tempconvert($row_log['brewTertiaryTemp'], "C") . "</TERTIARY_TEMP>\n"; }
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewTertiaryTemp'] != "")) { $xml_output .= "\t\t<TERTIARY_TEMP>" . $row_log['brewTertiaryTemp'] . "</TERTIARY_TEMP>\n"; }
		else $xml_output .= "\t\t<TERTIARY_TEMP></TERTIARY_TEMP>\n";
		
		if (($row_pref['measTemp'] == "F") && ($row_log['brewTertiaryTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_TERTIARY_TEMP>" . tempconvert($row_log['brewTertiaryTemp'], "C") . "</DISPLAY_TERTIARY_TEMP>\n"; }
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewTertiaryTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_TERTIARY_TEMP>" . $row_log['brewTertiaryTemp'] . "</DISPLAY_TERTIARY_TEMP>\n"; }
		else $xml_output .= "\t\t<DISPLAY_TERTIARY_TEMP></DISPLAY_TERTIARY_TEMP>\n";
		
		$xml_output .= "\t\t<AGE>" . $row_log['brewAge'] .  "</AGE>\n";
		if (($row_pref['measTemp'] == "F") && ($row_log['brewAgeTemp'] != "")) { $xml_output .= "\t\t<AGE_TEMP>" . tempconvert($row_log['brewAgeTemp'], "C") .  "</AGE_TEMP>\n"; }
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewAgeTemp'] != "")) { $xml_output .= "\t\t<AGE_TEMP>" . $row_log['brewAgeTemp'] . "</AGE_TEMP>\n"; }
		else { $xml_output .= "\t\t<AGE_TEMP></AGE_TEMP>\n";  }
	
		if (($row_pref['measTemp'] == "F") && ($row_log['brewAgeTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_AGE_TEMP>" . tempconvert($row_log['brewAgeTemp'], "C") .  "</DISPLAY_AGE_TEMP>\n"; }
		elseif (($row_pref['measTemp'] == "C") && ($row_log['brewAgeTemp'] != "")) { $xml_output .= "\t\t<DISPLAY_AGE_TEMP>" . $row_log['brewAgeTemp'] . "</DISPLAY_AGE_TEMP>\n"; }
		else { $xml_output .= "\t\t<DISPLAY_AGE_TEMP></DISPLAY_AGE_TEMP>\n";  }
		
		if ($source == "brewLog") {
		// Brew Date
		$xml_output .= "\t\t<DATE>" . $row_log['brewDate'] .  "</DATE>\n";
		}
		$xml_output .= "\t\t<EST_COLOR>" . round($row_log['brewLovibond'], 1) .  "</EST_COLOR>\n";
		$xml_output .= "\t\t<IBU>" . round($row_log['brewBitterness'], 1) .  "</IBU>\n";
    $xml_output .= "\t</RECIPE>\n"; 
$xml_output .= "</RECIPES>\n"; 
# This line will stream the file to the user rather than spray it across the screen
$nospace = str_replace(" ", "", $row_log['brewName'] );
$nospace = strtr($nospace, $html_remove);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$nospace.".xml");
header("Pragma: no-cache");
header("Expires: 0");
echo $xml_output;
exit();
?>
