<?php
	/*
	** File: add_sku
	** Description: form for creating a sku
	** Version: $Revision: 1.13 $
	** Created: 04/13/1999
	** Author: Leon Atkinson, Shannon -jj Behrens
	** Email: leon@clearink.com, jj@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/12/07 21:45:04 $
	** Log : $Log: add_sku,v $
	** Log : Revision 1.13  1999/12/07 21:45:04  leon
	** Log : All forms should be using StartForm now...
	** Log :
	** Log : Revision 1.12  1999/11/09 00:06:16  jj
	** Log : Changed the layout (ever so slightly) since it didn't look right.
	** Log :
	** Log : Revision 1.11  1999/11/08 22:32:20  leon
	** Log : Added prepareText() function to use everywhere we were using htmlentities.
	** Log :
	** Log : Revision 1.10  1999/10/12 23:14:45  leon
	** Log : Moved localization constants into 'english' module.  Added constant to
	** Log : control whether unregistered shoppers may checkout.
	** Log :
	** Log : Revision 1.9  1999/10/12 00:39:06  chris
	** Log : Moving text into constants in preparation of localization support.
	** Log :
	** Log : Revision 1.8  1999/08/18 22:32:11  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.7  1999/08/03 22:50:57  jj
	** Log : Doing quality control on department and items editors.
	** Log :
	** Log : Revision 1.6  1999/08/03 00:26:39  jj
	** Log : A large amount of programming changing the whole department and item admin process.
	** Log :
	** Log : Revision 1.5  1999/07/28 19:27:29  leon
	** Log : Mass update based on code donation from a live project
	** Log :
	** Copyright (c) 1999 Working Dogs.  All rights reserved.
	**
	** Expected Input: $item
	*/

	/* Make sure the user has admin rights. */
	if( !$UserInfo["Permission"]["Administrate"] )
	{
		print("Access denied!<BR>\n");
	}
	else if ($item <= 0)
	{
		print("I don't know which item to attach this sku to. This is a bug.");
	}
	else
	{
		/* Put everything in a nice border'ed table. */
		print("<TABLE WIDTH=\"100%\" BORDER=\"1\"><TR><TD>\n");
		
		/* Start the form and the organizational table. */
		print(StartForm("edit_item", 'post', 'ADD_SKU', FALSE, 
			array("item"=>$item)));

		print("<B>" . L_ADDSKU_ADDING . "</B><BR>\n");
		print("<TABLE>\n");
		
		print("<TR><TD>" . L_ADDSKU_EXTERNALSKU . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputExternalSKU\" SIZE=\"32\" ".
			"VALUE=\"");
		print(isset($inputExternalSKU) ? prepareText($inputExternalSKU) : "");
		print("\"></TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_NAME . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputName\" SIZE=\"32\" " . 
			"VALUE=\"");
		print(isset($inputName) ? prepareText($inputName) : "");
		print("\"></TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_LISTPRICE . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputListPrice\" SIZE=\"32\" " . 
			"VALUE=\"");
		print(isset($inputListPrice) ? prepareText($inputListPrice) : "");
		print("\"></TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_SALEPRICE . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputSalePrice\" SIZE=\"32\" " .
			"VALUE=\"");
		print(isset($inputSalePrice) ? prepareText($inputSalePrice) : "");
		print("\"></TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_SHIPPING . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputShipping\" SIZE=\"32\" " . 
			"VALUE=\"");
		print(isset($inputShipping) ? prepareText($inputShipping) : "");
		print("\"></TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_DISPLAYPRECEDENCE . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputDisplayPrecedence\" " . 
			"VALUE=\"");
		print(isset($inputDisplayPrecedence) ?
			prepareText($inputDisplayPrecedence) : "");
		print("\" SIZE=\"2\"></TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_INVENTORYAVAILABLE . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputAvailable\" SIZE=\"10\" " .
			"VALUE=\"");
		print(isset($inputAvailable) ? prepareText($inputAvailable) : "");
		print("\"></TR></TD>\n");

		print("<TR><TD>" . L_ADDSKU_INVENTORYRESERVE . "</TD>\n");
		print("<TD><INPUT TYPE=\"text\" NAME=\"inputReserve\" SIZE=\"10\" " .
			"VALUE=\"");
		print(isset($inputReserve) ? prepareText($inputReserve) : "");
		print("\"></TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_INVENTORYZERO . "</TD>\n");
		print("<TD><INPUT TYPE=\"checkbox\" NAME=\"inputBackorder\" " . 
			"VALUE=\"Y\"");
		print(isset($inputBackorder) && $inputBackorder=="Y" ? "CHECKED>":">");
		print("</TD></TR>\n");

		print("<TR><TD>" . L_ADDSKU_ACTIVE . "</TD>\n");
		print("<TD><SELECT NAME=\"inputActive\">\n");
		if (isset($inputActive) && $inputActive == "N")
		{
			print("<OPTION VALUE=\"Y\">Yes\n");
			print("<OPTION VALUE=\"N\" SELECTED>No\n");
		}
		else
		{	
			print("<OPTION VALUE=\"Y\" SELECTED>Yes\n");
			print("<OPTION VALUE=\"N\">No\n");
		}
		print("</SELECT></TD></TR>\n");

		/* Allow the user to choose among any variations that exist. */
		$Query = "SELECT a.Name, v.ID, v.Name ";
		$Query .= "FROM attribute a, variation v ";
		$Query .= "WHERE v.Attribute = a.ID ";
		$Query .= "ORDER BY a.DisplayPrecedence, a.Name, " . 
			"v.DisplayPrecedence, v.Name";
		$DatabaseResult = mysql_query($Query, $DatabaseLink);
		$last_attribute = "";
		while($DatabaseRow = mysql_fetch_row($DatabaseResult))
		{
			$attribute_Name = $DatabaseRow[0];
			$variation_ID = $DatabaseRow[1];
			$variation_Name = $DatabaseRow[2];
			if($last_attribute != $attribute_Name)
			{
				if($last_attribute != "")
				{
					print("</TD></TR>\n");
				}
				print("<TR><TD VALIGN=\"top\">" . prepareText($attribute_Name) . 
					"</TD><TD>\n");
				$last_attribute = $attribute_Name;
			}
			print("<INPUT TYPE=\"checkbox\" NAME=\"inputVariation[]\" " . 
				"VALUE=\"$variation_ID\"> ");
			print(prepareText($variation_Name) . " &nbsp; ");
		}

		/* Finish up the form and the inner table. */
		print("<TR><TD>\n");
		print("<INPUT TYPE=\"submit\" VALUE=\"" . L_ADDSKU_ADDSKU . "\">\n");
		print("<INPUT TYPE=\"reset\" VALUE=\"" . L_ADDSKU_RESET . "\">\n");
		print("</TD>\n");
		print("<TD ALIGN=\"right\"><A HREF=\"" . ScreenURL("admin_item") . 
			"&item=" . intval($item) . "\">Cancel</A></TD></TR>\n");
		print("</TABLE>\n");
		print("</FORM>\n");
		
		/* Finish up the outer table. */
		print("</TD></TR></TABLE>\n");
	}

?>
