<?php
	/*
	 *
	 *  Lennox.com Product API v1.0 Example
	 * 	PRODUCT DETAILS
	 *
	 *	XML Source: http://lennox.poweractive.com/api/v1/category/<categorynumber>/
	 *
	 *  PHP 5 w/ XML transport
	 *  Author: Ben Wilson (bwilson@powercreative.com)
	 *  2008/10/09
	 *
	 *  Version 1.0 - Initial write
	 *
	 *
	 *  Note: the "allow_url_fopen" directive in your php.ini file must be
	 *        set to "On" for this demo to work.
	 */

//$APIKEY = $_GET['apikey'];
include ('../db1.php');
$host = 'localhost'; 
$username = 'restaura_taste';
$password = 'Daughters2'; 
include("../../includes/mysql_connect.php");

	$len_qry = "select lennox_api_key from storePrefs";
	$rtl=mysql_query($len_qry);          // query executed
	while($ntl=mysql_fetch_array($rtl)){
		$lennox_api_key = $ntl['lennox_api_key'];
	}
				
	$APIKEY = $lennox_api_key;
				
//fetch MODEL from querystring													'
if (!empty($_GET['product'])) { $product_id = $_GET["product"]; }
else { echo "This script requires a valid model ID."; exit(); }

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>
    <title>Product Details - PHP - Lennox.com API Prototype</title>
	<style type="text/css">
		h2, div { margin: 0; padding: 0; }
		img { border: 0; }
		#ProductPhoto {
			float:	right;
			text-align:center;
		}
			#ProductPhoto div.content {
				margin: 0 25px 20px 20px;
			}
		img.CertLogo {
			margin: 0 5px;
		}
	</style>
	<script type="text/javascript">
		function basePopup(uri,width,height,winName,winArgs) {
			/* close existing popUp window */
			if (typeof(popUp) == "object") { if (typeof(popUp.window) == "object") { popUp.close(); }}

		    popUp = window.open(uri, winName, 'width=' + width + ',height=' + height + winArgs);

			/* attempt to focus the new window */
			if (typeof(popUp) == "object") {
				try {
				    popUp.focus();
				} catch(err) {
					return false;
				}
			}
			return false;
		}

		// A general-purpose popup window function
		function popupWindow(uri, width, height) {
		    var windowName = 'popup';
		    if(arguments.length > 3) {
		        windowName = arguments[3];
		    }

		    return basePopup(uri,750,600,windowName,',scrollbars=no,resizable=yes,menubar=no,toolbar=no,location=no,directories=no,status=no,menubars=no');
		}

		// A general-purpose popup window function with full chrome
		function popupScrollOnly(uri,width,height,windowName) {
		    return basePopup(uri,width,height,windowName,',scrollbars=yes,resizable=yes,menubar=no,toolbar=no,location=no');
		}

		function EnlargePhoto(filename) {
		    ///return popupScrollOnly('image-popup.php?filename=' + filename,610,570,'photo');
			return popupScrollOnly(filename,610,570,'photo');
		}

	</script>
</head>

    <body>
<?php
	//Lennox.com Product API URL for Product Categories
	$api_url = "http://www.lennox.com/api/v1/".$APIKEY."/product/".$product_id;
	
	//use the handy SimpleXML file loader
	$xml = simplexml_load_file($api_url);

	//SimpleXML will either return FALSE is unsuccessful
	//or an XML object if successful.
	if ($xml) {

		if ($xml->Product) {
			$product = $xml->Product;
?>
				<div id="ProductInfo">
					<div id="ProductPhoto">
						<div class="content">
							<a href="<?php echo $product->Images->LargeImage ?>" onclick="return EnlargePhoto(this.href);">
								<img src="<?php echo $product->Images->MediumImage ?>" alt="<?php echo $product->ShortName ?>" />
							</a>
							<br />&nbsp;<br />
							<a href="<?php echo $product->Images->LargeImage ?>" onclick="return EnlargePhoto(this.href);">View Larger</a>
							<br />

<?php
				//if this PRODUCT has an ANIMATION attached to it, then
				//show the ANIMATION POPUP link ("look inside")
				if ($product->Animations) {
					foreach ($product->Animations->Animation as $anim) {
?>
							<!--<a href="animation-popup.php?filename=<?php //echo $anim->Filename ?>&amp;width=<?php //echo $anim->Width ?>&amp;height=<?php //echo $anim->Height ?>&amp;bgcolor=<?php //echo $anim->attributes()->BGColor ?>" onclick="return popupWindow(this.href,<?php //echo $anim->Width ?>,<?php //echo $anim->Height ?>);">-->
							<br><a href="<?php echo $anim->Filename ?>" onclick="return popupWindow(this.href);">
							<?php echo $anim->Label ?>
							</a>
<?php
					} //foreach Anim
				} //if Anims
?>
						</div>
					</div><!--/end PRODUCTPHOTO div-->

					<h2>

<?php
				//does the product have a series (e.g. Dave Lennox Signature Collection)
				if ($product->Series) {
					//should we display the Series Name?
					if ($product->Series->attributes()->Display == "Y") {
?>
					<?php echo $product->Series ?>&nbsp;
<?php
					} //if Series is to be displayed
				} // if Series
?>
				<?php echo $product->ModelName ?>
				</h2>

				<div><?php echo $product->OneLiner ?></div>

				<h3>Features</h3>
<?php
				//check for product features
				if ($product->Features) {

					//show each feature
					foreach ($product->Features->Feature as $feature) {
?>
				<h4><?php echo $feature->Title ?></h4>
				<ul>
					<?php echo $feature->Body ?>
				</ul>
<?php
					} //foreach Feature

				} //if Features

				//check for product features
				if ($product->Publications) {
?>
					<h3>Publications</h3>

<?php

					//show each feature
					foreach ($product->Publications->Publication as $pub) {

?>
						<a href="<?php echo $pub->URL ?>"><?php echo $pub->Name ?></a><br />
<?php

					} //foreach

				} // if Publications


				//check for product features
				if ($product->Certifications) {
?>
					<h3>Certifications</h3>

<?php

					//show each feature
					foreach ($product->Certifications->Certification as $cert) {

?>
					<img class="CertLogo" src="http://www.lennox.com/res/images/logo_<?php echo strtolower($cert->attributes()->Code) ?>.jpg" alt="<? echo $cert ?>" />
<?php

					} //foreach

				} // if Certifications
?>



				</div><!--/end PRODUCT INFO div-->

<?php
		} //if Product

	} else {
		echo "There has been an error retrieving the XML.";
		exit();
	}

?>

    </body>
</html>
