<?php
	/*
	** File: contents
	** Description: review of basket, link to complete order
	** Version: 1.1
	** Created: 04/23/1999
	** Author: Leon Atkinson
	** Email: leon@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 2000/02/05 00:23:47 $
	** Log : $Log: contents,v $
	** Log : Revision 1.12  2000/02/05 00:23:47  leon
	** Log : Removing number_format in favor of formatMoney
	** Log :
	** Log : Revision 1.11  1999/12/07 21:45:08  leon
	** Log : All forms should be using StartForm now...
	** Log :
	** Log : Revision 1.10  1999/11/09 00:28:16  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:23  leon
	** Log : Added prepareText() function to use everywhere we were using htmlentities.
	** Log :
	** Log : Revision 1.8  1999/10/12 23:14:49  leon
	** Log : Moved localization constants into 'english' module.  Added constant to
	** Log : control whether unregistered shoppers may checkout.
	** Log :
	** Log : Revision 1.7  1999/10/12 00:39:09  chris
	** Log : Moving text into constants in preparation of localization support.
	** Log :
	** Log : Revision 1.6  1999/10/04 22:09:55  leon
	** Log : Removed getInvoiceID.  The active invoice is now added to $UserInfo
	** Log : by the check sid functionality in init.
	** Log :
	** Log : Revision 1.5  1999/08/18 22:32:14  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.4  1999/07/28 19:27:30  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");


	//show basket contents
	$Query = "SELECT ss.ID, s.ExternalSKU, s.Name, s.ListPrice, " . 
		"s.SalePrice, i.Name, ss.Quantity, s.Shipping, ss.Notes ";
	$Query .= "FROM session_sku ss, sku s, item i ";
	$Query .= "WHERE ss.SKU = s.ID ";
	$Query .= "AND s.Item = i.ID ";
	$Query .= "AND ss.Session = '$sid' ";
	
	$DatabaseResult = mysql_query($Query, $DatabaseLink);
	

	if(mysql_numrows($DatabaseResult))
	{
		print(StartForm("contents", 'post', 'UPDATE_BASKET', FALSE));


		print("<TABLE BORDER=\"0\">\n");
		
		print("<TR>\n");
		print("<TH>" . L_CONTENTS_ITEM . " (" . L_CONTENTS_SKU . ")</TH>\n");
		print("<TH>" . L_CONTENTS_PRICE . "</TH>\n");
		print("<TH COLSPAN=\"2\">" . L_CONTENTS_QUANTITY . "</TH>\n");
		print("</TR>\n");

		print("<TR>\n");
		print("<TD COLSPAN=\"5\"><HR></TD>\n");
		print("</TR>\n");

		while($DatabaseRow = mysql_fetch_row($DatabaseResult))
		{
			$sku_ID = $DatabaseRow[0];
			$sku_ExternalSKU = $DatabaseRow[1];
			$sku_Name = $DatabaseRow[2];
			$sku_Price = $DatabaseRow[3];
			$sku_SalePrice = $DatabaseRow[4];
			$item_Name = $DatabaseRow[5];
			$basket_Quantity = $DatabaseRow[6];
			$sku_Shipping = $DatabaseRow[7];
			$sku_Variation = unserialize($DatabaseRow[8]);
	
			if($sku_SalePrice > 0)
			{
				$sku_Price = $sku_SalePrice;
			}
	
			print("<TR>\n");
			print("<TD>");
			print(prepareText($item_Name) . " (" . 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>");
			print(formatMoney($sku_Price));
			if($sku_Shipping > 0)
			{
				print(" (");
				print(formatMoney($sku_Shipping));
				print(")");
			}
			print("</TD>\n");
	
			print("<TD>");
			print("<INPUT TYPE=\"text\" SIZE=\"3\" ");
			print("NAME=\"inputBasket[$sku_ID]\" ");
			print("VALUE=\"$basket_Quantity\">");
			print("</TD>\n");

			/* 
			** Give the user a link to completely remove the item from his
			** basket.
			*/			
			print("<TD>");
			print("<a href=\"" . ScreenURL("contents") . "&");
			print("ACTION=UPDATE_BASKET&");
			print("inputBasket[$sku_ID]=0\">");
			print(L_CONTENTS_DELETE . "</a>");
			print("</TD>");

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

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


		print("<TR>\n");
		print("<TD COLSPAN=\"5\" ALIGN=\"right\">");
		print("<INPUT TYPE=\"SUBMIT\" VALUE=\"" . L_CONTENTS_UPDATEQUANTITIES . "\">");
		print("</TD>\n");
		print("</TR>\n");

		print("</TABLE>\n");
	
	
		print("</FORM>\n");

		// only users who are logged in may use the wishlist
		if(isset($UserInfo["ID"]) && $UserInfo["ID"]>0 )
		{ 
			print("<A HREF=\"" . ScreenURL("wishlist") . "&amp;ACTION=SAVE_BASKET\">");
			print(L_CONTENTS_SAVEENTIREBASKET);
			print("</A><BR>\n");
		
		}
		elseif(SHOPPER_MUST_REGISTER)
		{
			//if shoppers must register, show special message.

			print(L_CONTENTS_TOPURCHASEITEMS . "<BR>\n");
			
			print("<A HREF=\"" . ScreenURL("create_account") . "\">");
			print(L_CONTENTS_REGISTER);
			print("</A><BR>\n");
			
			print("<A HREF=\"" . ScreenURL("login") . "\">");
			print(L_CONTENTS_LOGIN);
			print("</A><BR>\n");
		}
		
	}
	else
	{
		print("<BR>\n");
		print("<B>" . L_CONTENTS_BASKETISEMPTY . "</B><BR>\n");
	}	


	print("<BR>\n");

	if(isset($UserInfo['Invoice']) AND ($UserInfo['Invoice'] > 0))
	{
		print(L_CONTENTS_UNFINISHEDINVOICE . "<BR>\n");
		
		print("<A HREF=\"" . ScreenURL("order_info", TRUE, array('ACTION'=>'CLEAN_INVOICE_FULL')). "\">");
		print(L_CONTENTS_CONTINUE);
		print("</A><BR>\n");
		
		print("<A HREF=\"" . ScreenURL("contents") . "&amp;ACTION=PURGE_INVOICE\">");
		print(L_CONTENTS_CLEAROUT);
		print("</A><BR>\n");
	}

	print("<BR>\n");

	/* 
	** Give the user a link to return to shopping. Try to return him
	** to the department he was in.
	*/
	if (isset($department))
	{
		print("<A HREF=\"" . ScreenURL("department"));
		print("&department=" . intval($department));
		print("\">");
		print(L_CONTENTS_CONTINUESHOPPING);
		print("</A><BR>\n");
	}

?>
