<?
// Time the page execution.
$START_TIME = array_sum(explode(" ",microtime()));

// global $SQL_DEBUG;
// $SQL_DEBUG = TRUE;

include_once "myshop.php";
include_once "shopFunctions.php";

//global $SQL_DEBUG;
//$SQL_DEBUG = TRUE;

//////////////////////////////////////////////////////////////////////////////////////////

ClearBasketIfSubmitted();

//////////////////////////////////////////////////////////////////////////////////////////

$store = Store::Instance();

$HOME_OPTION = HOME_NORMAL;
$SUBMENUS = "";
$imagesArr = array();
$showFlash = false;

if (isset($catID))
{
	$HOME_OPTION = HOME_CATEGORY;
}
else
{
	$catID = 0;
}

if (isset($productID))
{
	$HOME_OPTION = HOME_PRODUCT;
}
else
{
	$productID = 0;
}

if (isset($search_criteria) || isset($search_keyword) || isset($search_name) || isset($search_season) || isset($search_colour))
{
	$HOME_OPTION = HOME_SEARCH;
}

$packageID = 0;

if (isset($_SERVER["SCRIPT_URI"]) &&  $_SERVER["SCRIPT_URI"] != "")
{
	$urlinfo = $_SERVER["SCRIPT_URI"];
}
else if (isset($_SERVER["PATH_TRANSLATED"]))
{
	$urlinfo = $_SERVER["PATH_TRANSLATED"];
	$urlinfo = str_replace("web/","web/shop/", $urlinfo);
}
else
{
	$urlinfo = "";
}

$start = strpos($urlinfo, "shop/");

if ($start)
{
	$start += 5;

	$len = strlen($urlinfo);

	if ($urlinfo[$len - 1] == '/')
	{
	    $len--;
	}

	$locationTxt = substr( $urlinfo, $start, $len-$start);

	if (strlen($locationTxt)>3 && $catID == 0)
	{
		$tempInt = intval(substr($locationTxt, 3, strlen($locationTxt)-3));
		$tempStr = substr($locationTxt, 0, 3);

		if ($tempStr == "cat")
		{
			$HOME_OPTION  = HOME_CATEGORY;
			$catID = $tempInt;

			if($catID == 0)
			{
				$HOME_OPTION = HOME_NORMAL;
			}
		}
		else if ($tempStr == "off")
		{
			$HOME_OPTION = HOME_OFFERS;
		}
		else if ($tempStr == "prd")
		{
			$HOME_OPTION = HOME_PRODUCT;
			$productID = $tempInt;
		}
		else if ($tempStr == "inf")
		{
			$HOME_OPTION = HOME_INFO;

			if (strlen($locationTxt)>13)
			{
				$pageID = substr($locationTxt, 12, strlen($locationTxt)-12);
			}
			else
			{
				$pageID = "";
			}
		}
		else if ($tempStr == "adv")
		{
			$HOME_OPTION = HOME_ADVSEARCH;
		}
	}
}

$cat = NULL;
$title = "";
$description = "";
$keyword = "";

if ($catID != 0)
{
	$cat = new ProductCategory();
	$cat->OpenId($catID);
	$title .= $cat->getName();
	$title .= " - ";
	$keyword = $cat->GetFullPathName(',') . ",";
	$description = $cat->getName();
}

if ($productID != 0)
{
	$product = new Product();
	$product->OpenId($productID);
	$cat = new ProductCategory();
	$cat->OpenId($product->GetCatId());
	$catID = $cat->GetID();

	$summary = $product->getSummary();
	$path = $cat->GetFullPathName(',');

	// $title .= $product->getName() . " - " . $cat->GetFullPathName('&nbsp;-&nbsp;'). " - ";
	// $keyword = $product->getName() . "," . $cat->GetFullPathName(',') . ",";
	// $description = $product->getName() . " at " ;

	$title .= $summary . ' - ' . $path . " - ";
	$keyword = $summary . "," . $path . ",";
	$description = $product->GetName() . " at " ;
}

//$MAIN_CAT_ARR = $store->GetProductCategories(PRODCAT_TOP_LEVEL_ID);

$menu = getMenu();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta name="MSSmartTagsPreventParsing" content="true" />
	<link rel="stylesheet" type="text/css" href="/ffocus-css.php" />
	<script src="/ffocus.js" type="text/javascript"></script>
	<title><?=$title; ?>flower photography, and plant photography image library, art on demand, buy flower prints, and flower canvases of flower photographs</title>
	<meta name="verify-v1" content="prVb7mXXnoJUI0DF+nFUX9ZlrULtgJcOZZoLx7MB0Z4=" />
	<meta name="keywords" content="<?=$keyword;?>, Flower photography, Flower Pictures, Flower photographs, flower photography, plant photography, flower prints, flower canvases, image library, flower pictures, flower portraits, flower photos, purchase photographic prints, canvases, flowers on canvas, buy frames, buy prints, buy online or by phone, UK" />
	<meta name="description" content="<?=$description;?> flower photography, plant photography, image library, art on demand, purchase flower prints and flower canvases, abstract flower pictures, greetings cards, contemporary fine art, frames, buy frames " />
</head>

<body onLoad="initFoldout();<?=($UNFOLD_MENU>-1 ? 'menu('.$UNFOLD_MENU.');' : ''); ?>">

<?
/*
<noscript>
// put search engine stuff in here too...
</noscript>
*/

// $SQL_DEBUG = TRUE;
?>
<div id="center-page">
	<div id="page">
		<div id="content" >
			<div id="clear1"><img src="/Images/clear.gif" id="clear1" /></div>
			<div id="left-outer-content">
				<br />
				<br />
				<br />
				<div id="left-content"><br /></div>
			</div>

			<div id="right-content">
			<?
			// MENU SETUP
			if ($catID == 0)
			{
				/*
				$cat_tree = $store->GetCategoryTree();
				$products = $store->GetProductsFromCategoryTree($cat_tree);

				$number = 20;

				if (count($products) < $number)
				{
					$number = count($products);
				}

				$foundProducts = array();

				$keys = array_keys($products);
				$productCount = count($keys);

				while( $number )
				{
					$num = rand(0,$productCount - 1);

					if( !isset($foundProducts[$keys[$num]]) )
					{
						if( $products[$keys[$num]]->GetCatId()!="11" )
						{
							$foundProducts[$keys[$num]] = $products[$keys[$num]];
							$number--;
						}
					}
				}
				*/
				//$foundProducts = $store->FindProducts( "white", DBO_ANY, TRUE, DBO_SEARCH_AND, DBO_NO_OFFSET, DBO_NO_LIMIT, DBO_NO_ORDER_BY );
				$foundProducts = $store->GetRandomProducts( 20 );

			}
			else
			{
				//die("got cat");

				//$cat_tree = $store->GetCategoryTree($catID);
				//$foundProducts = $store->GetProductsFromCategoryTree($catID);
				//$foundProducts = $store->GetProductsByCategory($catID);

				if( isset($display_ids) ) //if hidden var isnt set, do this
				{
						$foundProducts= Array();
						$display_ids = explode( ",", $display_ids );
						foreach( $display_ids as $num )
						{
							$product = new Product();
							$product->OpenId( $num );
							$foundProducts[$num]= $product;
						}
				}
				else
				{
					$foundProducts = $store->FindProducts( DBO_ANY, $catID, TRUE, DBO_SEARCH_AND );
				}

			}

			// SIMPLE SEARCH
			if (isset($search_criteria) && $search_criteria != "keywords")
			{
				$search_criteria = stripslashes($search_criteria);

				$foundProducts = $store->FindProducts($search_criteria, DBO_ANY, TRUE, DBO_SEARCH_AND);


				if (count($foundProducts) > 0)
				{
					$searchMsg = "Found " . count($foundProducts) . " pictures matching '" . $search_criteria . "'";
				}
				else
				{
					$searchMsg = "Sorry no pictures matched '" . $search_criteria . "'.";
				}

				/*
				$product_ids = $store->FindProductIds($search_criteria, TRUE, DBO_SEARCH_AND);

				if (count($product_ids) > 0)
				{
					$searchMsg = "Found " . count($product_ids) . " pictures matching '" . $search_criteria . "'";

					$foundProducts = array();

					foreach ($product_ids as $prod_id)
					{
						$product = new Product();
						$product->OpenId($prod_id);
						array_push($foundProducts, $product);
					}
				}
				else
				{
					$searchMsg = "Sorry no pictures matched '" . $search_criteria . "'.";
				}
				*/
			}
			// ADVANCED SEARCH
			else if (isset($search_name) || isset($search_season) || isset($search_keyword) || isset($search_colour))
			{
				$search_text = "";

				$lists = array();

				if ($search_name != "")
				{
					$search_text .= stripslashes($search_name) . " ";
				}

				if ($search_keyword != "")
				{
					$search_text .= stripslashes($search_keyword) . " ";
				}

				if (intval($search_season) != 0)
				{
					// $search_text .= $search_season . " ";
					$lists['season'] = $search_season;
				}

				if (intval($search_colour) != 0)
				{
					// $search_text .= $search_colour;
					$lists['colour'] = $search_colour;
				}

				//print "[".$search_text."]";
//global $SQL_DEBUG;
//$SQL_DEBUG = TRUE;

				$foundProducts = $store->FindProducts($search_text, DBO_ANY, TRUE, DBO_SEARCH_AND, DBO_NO_OFFSET, DBO_NO_LIMIT, DBO_NO_ORDER_BY, $lists );

//$SQL_DEBUG = FALSE;

				if (count($foundProducts) > 0)
				{
					$searchMsg = "Found " . count($foundProducts) . " pictures matching '" . $search_text . "'";
				}
				else
				{
					$searchMsg = "Sorry no pictures matched '" . $search_text . "'.";
				}

				/*
				$product_ids = $store->FindProductIds($search_text, TRUE, DBO_SEARCH_AND);

				if (count($product_ids) > 0)
				{
					$searchMsg = "Found " . count($product_ids) . " pictures matching '" . $search_text . "'";
					$foundProducts = array();

					foreach ($product_ids as $prod_id)
					{
						$product = new Product();
						$product->OpenId($prod_id);
						array_push($foundProducts, $product);
					}
				}
				else
				{
					$searchMsg = "Sorry no pictures matched '" . $search_text . "'.";
				}
				*/
			}

			if ($productID == 0)
			{
				$foundProductTemp = $foundProducts;
				$product = array_shift($foundProductTemp);
				$foundProductTemp = NULL;

				if (is_object($product))
				{
					$productID = $product->getID();
				}
				else
				{
					$productID = 0;
				}
			}
			else
			{
				$product = new Product();
				$product->OpenID($productID);
			}

			switch ($HOME_OPTION)
			{
				case HOME_NORMAL:
					$shopExtra = $store->getShopExtraByKey("welcome");
					?>
					<table width="100%" cellpadding="5" border="0"><tr><td colspan="2" valign="top" align="right"><span class="txt10"><b>home</b></span></td></tr><tr><td valign="top">
					<span class="txt10"><b><?=$shopExtra->getName(); ?></b></span><br />
					<br />
					<?=$shopExtra->getHTML(); ?>
					</td><td valign="top">
					<?
					$details =  $product->getDetails();

					if (isset($details["picture"]))
					{
						$detail = $details["picture"];

						if (($id = $detail->GetIntValue()) != 0)
			        	{
					        $imfile = new File();
					        $imfile->OpenId($id);

							print '<img src="' . $imfile->GetFileNameWithPath() . '" border="0">';
			        	}
			        }
					?>
					</span></td></tr>
					</table>
					<?
					break;
				case HOME_CATEGORY:
				case HOME_PRODUCT:
				case HOME_SEARCH:
					if (!is_object($product))
					{
						print "<br /><br /><br /><p>Sorry, there are currently no products in this category.</p>";
					}
					else
					{
						$productDetails = $product->GetDetails();
						?>
						<table width="100%" cellspacing="5" cellpadding="0" border="0">
							<tr>
								<td align="right">
								<span class="txt10">&nbsp;&nbsp;<b>
								<?
									if ($cat != NULL)
									{
										print $cat->GetFullPathName('&nbsp;&gt;&nbsp;');
									}
									else if (isset($searchMsg))
									{
										print $searchMsg;
									}
								?>
								&nbsp;&nbsp;</b></span>
								</td>
							</tr>
							<tr>
								<td>
									<form id="buyform" name="buyform" action="/shop/prd<?=$productID?>" method="post">
									<input type="HIDDEN" name="buy" value="true" />
									<input type="HIDDEN" name="basketname" value="basket/lightbox" />
									<input type="HIDDEN" name="productID" value="<?=$productID; ?>" />
									<?
									$html = $product->GetFormatted();

									$html = str_replace("&pound;999.00", "add to lightbox", $html);
									$html = str_replace("TBA", "To calculate price, please select a product from the menu above.", $html);

									print $html;
									?>
									</form>
								</td>
							</tr>
						</table>
						<?
					}
					break;

				case HOME_INFO:
					$shopExtra = $store->getShopExtraByKey($pageID);
					if ($shopExtra == NULL)
					{
					?>
					<br />
					<br />
					<table width="100%" cellpadding="5" border="0">
						<tr>
							<td>
							<span class="txt10"><b>Information Page</b>
							<br /><br />
							Sorry this page could not be found.
							<br />
							</span>
							</td>
						</tr>
					</table>
					<? } else { ?>
					<br />
					<br />
					<table border="0" width="600" >
						<tr>
							<td>
								<img src="/Images/clear.gif" width="0" height="250" />
							</td>
							<td valign="top">
								<table width="100%" cellpadding="5" border="0">
									<tr>
										<td>
											<span class="txt10"><b><?=$shopExtra->getName(); ?></b>
											<br /><br />
											<?=$shopExtra->GetHTML()?>
											<br />
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
					<?
					}
					break;

				case HOME_ADVSEARCH:
					$store = Store::Instance();
					$dlists = $store->GetProductDetailListsByKey();
					?>
					<form id="advancedsearch" action="/shop" method="get">
						<table width="100%" cellpadding="5" border="0">
							<tr>
								<td colspan="5" valign="top" align="right">
									<span class="txt10"><b>advanced search</b></span>
								</td>
							</tr>
							<tr>
								<td colspan="5" valign="top">
									<span class="txt10"><b>search on one or more of the following:</b></span>
									<br /><br />
								</td>
							</tr>
							<tr>
								<td width="22%" valign="top">
									common name or latin name:
								</td>
								<td width="20%" valign="top">
									<input type="text" name="search_name" />
								</td>
								<td width="15%" valign="top">
									&nbsp
								</td>
								<td valign="top">
									season:
								</td>
								<td width="30%" valign="top">
									<?
									$season_combo = new Combo();
									$season_combo->SetName("search_season");
									$season_combo->SetWidth("150");

									/*
									if (isset($dlists["season"]))
									{
										foreach ($dlists["season"]->GetItemsById() as $id=>$list)
										{
											$season_combo->SetRow($list->GetValue(), $list->GetValue());
										}
									}
									*/

									$season_combo->SetData( $dlists["season"]->GetItemsById() );
									$season_combo->SetFunction( 'GetValue' );
									$season_combo->SetDefaultEntry( 'Any' );
									// $season_combo->SetRow("Any", "any");

									$season_combo->outputHtml();
									?>
								</td>
							</tr>
							<tr>
								<td width="22%" valign="top">
									keyword:
								</td>
								<td width="20%" valign="top">
									<input type="text" name="search_keyword" />
								</td>
								<td width="15%" valign="top">
									&nbsp
								</td>
								<td valign="top">
									colour:
								</td>
								<td width="30%" valign="top">
									<?
									$colour_combo = new Combo();
									$colour_combo->SetName("search_colour");
									$colour_combo->SetWidth("150");
									// $colour_combo->SetRow("Any", "any");

									/*
									if (isset($dlists["colour"]))
									{
										foreach ($dlists["colour"]->GetItemsById() as $id=>$list)
										{
											$colour_combo->setRow($list->GetValue(), $list->GetValue());
										}
									}*/

									$colour_combo->SetData( $dlists["colour"]->GetItemsById() );
									$colour_combo->SetFunction( 'GetValue' );
									$colour_combo->SetDefaultEntry( 'Any' );

									$colour_combo->outputHtml();
									?>
								</td>
							</tr>
							<tr>
								<td colspan="5" valign="top" align="right">
									<a href="javascript: document.getElementById('advancedsearch').submit();">&gt;&gt; search</a>
								</td>
							</tr>
						</table>
					</form>
					<?
					break;
			}
			?>
			</div>
		</div>
		<div id="footer">
			<table width="100%">
				<tr>
					<td width="76"><img src="/Images/biz-hp-logo.gif" width="76" height="53"></td>
					<td><span class="txt10">website design by <A HREF="http://www.fine-focus.co.uk">fine-focus</A></span></td>
					<td align="right"><span class="txt8">Site and all Images &copy; 2002-2008 Claudine Fignon. All rights reserved.</span></td>
				</tr>
			</table>
		</div>

		<div id="finefocus-logo-layer">
			<a href="/" ><img src="/Images/finefocus-logo.gif" id="finefocus-logo" alt="finefocus.com" /></a>
		</div>

		<!--div id="basket"><?= getBasketInfo(); ?></div-->

		<div id="search"><?= getSearchBox( join( ',', array_keys($foundProducts) ) ); ?></div>

		<div id="lightbox">
<?
/*
			<div id="lightbox-image-container">
				<div id="lightbox-border">
					<div id="lightbox-border">
						<div id="lightbox-images">

							<table cellpadding="0" cellspacing="0">
								<tr>
									$first = true;

									foreach ($foundProducts as $product)
									{
										if (!$first)
										{
											print "<td><img src=\"/Images/clear.gif\" width=\"5\" /></td>";
										}
										else
										{
											$first = false;
										}

										print "<td>" . $product->GetFormatted(LS_LAYOUT_THUMBNAIL) . "</td>";
									}
									?>
								</tr>
							</table>
*/
							foreach ($foundProducts as $product)
							{
								print $product->GetFormatted(LS_LAYOUT_THUMBNAIL);
							}
/*
?>
						</div>
					</div>
				</div>
				<?
*/
				/*
				<div id="lightbox-image-container2">
					<div id="lightbox-images"><table width="100%" cellpadding="0" cellspacing="0" border="1"><tr><td><table height="70" cellpadding="0" cellspacing="0" border="0"><tr><?
						$first = true;

						foreach( $foundProducts as $product )
						{
							if(!$first)
							{
								print "<td><img src=\"/Images/clear.gif\" width=\"5\" /></td>";
							} else {
								$first = false;
							}

							print "<td>" . $product->GetFormatted(LS_LAYOUT_THUMBNAIL) . "</td>";
						}
					?></tr></table></td></tr><tr><td><img src="/Images/lightbox-bottom.gif" height="4" width="100%" border="0"></td></tr></table>
				</div>
			</div>
				*/
				?>
		</div>

		<div id="basketinfo"><?=getBasketInfo() ?></div>

		<?=$menu ?>

	</div>
</div>

<!--
<?
global $START_TIME;
global $MAX_MEM_USAGE;
global $db_stats_query_count;
print 'memory usage: '.number_format($MAX_MEM_USAGE/(1024*1024),2)."Mb\n";
print "database queries: ".$db_stats_query_count."\n";
print "execution time: ".number_format(array_sum(explode(" ",microtime()))-$START_TIME,3)." seconds\n";
?>
-->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1247234-2";
urchinTracker();
</script>
</body>
</html>

<?

//////////////////////////////////////////////////////////////////////////////

function getBasketInfo()
{
    $itemCount = 0;
    $id    = 0;
    $price = 0.00;
	$html  = "";

    if (hasBasket())
    {
    	$basket = getBasket();

    	$id = $basket->getId();
    	$itemCount = $basket->GetItemCount();
		//$price = $basket->GetGrossItemsCost();
		//$symbol = $basket->GetCurrencyHTML();
        $t = time();

        // This needs to be false but for now it will be fixed to true
		$lightbox = "";

		if ($itemCount > 0)
		{
			$items = $basket->GetItems();
			foreach ($items as $item)
			{
				if ($item->GetGrossCost() == 999)
				{
					$lightbox = TRUE;
				}
			}
		}
		else
		{
			return ("");
		}

		$displayTxt = "&gt;&gt; view " . ($lightbox ? 'lightbox' : 'basket');

$html=<<<BASKET
        <table cellpadding="0" cellspacing="0" border="0"><tr><td align="right"><form id="basketForm" name="basketForm" action="/Order/index.php?t=$t" method="post"><input type="hidden" name="basket_id" value="$id" /><input type="hidden" name="lightbox" value="$lightbox" /><a href="javascript:document.getElementById('basketForm').submit();"><b>$displayTxt</b></a></form></td></tr></table>
BASKET;
    }

	return ($html);
}
?>
