<?php
	/*
	** File: wishlist
	** Description: show wishlist, allow moving to basket
	** Version: $Revision: 1.12 $
	** Created: 06/10/1999
	** Author: Leon Atkinson
	** Email: leon@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 2000/02/05 00:23:49 $
	**
	** Log : $Log: wishlist,v $
	** Log : Revision 1.12  2000/02/05 00:23:49  leon
	** Log : Removing number_format in favor of formatMoney
	** Log :
	** Log : Revision 1.11  1999/12/07 21:45:11  leon
	** Log : All forms should be using StartForm now...
	** Log :
	** Log : Revision 1.10  1999/11/09 00:28:19  leon
	** Log : Changed use of notes column.  This column now stores an array of variation
	** Log : IDs in serialized form.  Names for attributes and variations are pulled
	** Log : from the database using two new functions in the attribute_functions
	** Log : include module.
	** Log :
	** Log : Revision 1.9  1999/11/08 22:32:31  leon
	** Log : Added prepareText() function to use everywhere we were using htmlentities.
	** Log :
	** Log : Revision 1.8  1999/10/12 22:39:38  leon
	** Log : Added support for language modules.  Note that while the structure is in
	** Log : place, efforts to move text out of screen and action modules is still
	** Log : underway.
	** Log :
	** Log : Revision 1.7  1999/10/11 18:01:41  leon
	** Log : Pulling text into constants in preparation of building localization
	** Log : module.
	** Log :
	** Log : Revision 1.6  1999/09/30 18:33:16  jj
	** Log : Anonymous users are no longer allowed to look at wishlists (via wishlist screen).
	** Log :
	** Log : Revision 1.5  1999/08/18 22:32:23  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.4  1999/07/28 19:27:35  leon
	** Log : Mass update based on code donation from a live project
	** Log :
	**
	** Copyright (c) 1999 Working Dogs.  All rights reserved.
	*/

	//get attribute functions
	include(APPLICATION_ROOT . "/modules/include/attribute_functions");


	/* Our halt flag. */
	$continueScript = TRUE;
	
		
	/*
	** Anonymous users have no wishlist. 
	*/
	if ($UserInfo["ID"] <= 0)
	{
		print(L_WISHLIST_LOGIN_TO_VIEW . "<BR>\n");
		$continueScript = FALSE;
	}
	
	
	
	/*
	** Get the list of stuff in the wish list.
	*/
	if ($continueScript)
	{
		$Query = "SELECT s.ID, s.ExternalSKU, s.Name, s.ListPrice, ";
		$Query .= "s.SalePrice, i.Name, us.Notes, us.ID ";
		$Query .= "FROM session, user_sku us, sku s, item i ";
		$Query .= "WHERE us.SKU = s.ID ";
		$Query .= "AND s.Item = i.ID ";
		$Query .= "AND session.ID = '$sid' ";
		$Query .= "AND session.User = us.User ";
		$DatabaseResult = mysql_query($Query, $DatabaseLink);

		/*
		** It's possible that there is nothing in the wishlist, in which case
		** we should output such a message, rather than simply outputting an
		** empty table.
		*/
		if (!mysql_num_rows($DatabaseResult))
		{
			print(L_WISHLIST_EMPTY);
		}
		/* Otherwise, output a nice table for the items in the wishlist. */
		else
		{
			print("<TABLE>\n");
			print("<TR>\n");
			print("<TD ALIGN=\"center\"><B>".L_WISHLIST_ITEM."</B></TD>\n");
			print("<TD ALIGN=\"center\"><B>".L_WISHLIST_DETAIL."</B></TD>\n");
			print("<TD ALIGN=\"center\"><B>".L_WISHLIST_PRICE."</B></TD>\n");
			print("<TD ALIGN=\"center\" COLSPAN=\"2\">" . 
				"<B>".L_WISHLIST_ACTION."</B></TD>\n");
			print("</TR>\n");
			print("<TR><TD COLSPAN=\"5\"><HR WIDTH=\"100%\"></TD></TR>\n");

			/* Output a row for each item in the wishlist. */
			while($DatabaseRow = mysql_fetch_row($DatabaseResult))
			{
				list($sku_ID, $sku_ExternalSKU, $sku_Name, $sku_Price, $sku_SalePrice, 
					$item_Name, $sku_Variation, $user_sku_ID) = $DatabaseRow;
					
				$sku_Variation = unserialize($sku_Variation);
					
				$sku_Price = ($sku_SalePrice > 0) ? $sku_SalePrice : $sku_Price;

				print("<TR><TD VALIGN=\"top\">");
				print(prepareText($item_Name));
				print("</TD>\n");

				print("<TD VALIGN=\"top\">");
				print(prepareText($sku_Name));
				
				if(is_array($sku_Variation))
				{
					while(list($key, $variation_ID) = each($sku_Variation))
					{
						print("<BR>\n");
						
						$variation = getVariationInfo($variation_ID);
						$attribute = getAttributeInfo($variation["Attribute"]);
						
						print(prepareText($attribute["Name"] . ": " . $variation["Name"]));
					}
				}

				print("</TD>\n");

				print("<TD VALIGN=\"top\">" . 
					formatMoney($sku_Price) . "</TD>\n");

				//submit button for adding item to basket
				print("<TD VALIGN=\"top\">");
				print(StartForm("wishlist", 'post', 'ADD_FROM_WISHLIST', FALSE, 
					array("input_ID"=>"$user_sku_ID")));
				print("<INPUT TYPE=\"submit\" value=\"".L_WISHLIST_ADD_BASKET."\">");
				print("</FORM>\n");
				print("</TD>\n");

				//delete button
				print("<TD VALIGN=\"top\">");
				print(StartForm("wishlist", 'post', 'REMOVE_FROM_WISHLIST', FALSE, 
					array("input_ID"=>"$user_sku_ID")));
				print("<INPUT TYPE=\"submit\" value=\"".L_WISHLIST_REMOVE."\">");
				print("</FORM>\n");

				print("</TD>\n");
				print("</TR>\n");
			}
			print("<TR><TD COLSPAN=\"5\"><HR WIDTH=\"100%\"></TD></TR>\n");
			print("</TABLE>\n");
		}
	}

?>
