<?php
	/*
	** File: admin_attribute
	** Description: administrate attributes
	** Version: $Revision: 1.7 $
	** Created: 04/21/1999
	** Author: Leon Atkinson
	** Email: leon@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/11/08 22:32:20 $
	** Log : $Log: admin_attribute,v $
	** Log : Revision 1.7  1999/11/08 22:32:20  leon
	** Log : Added prepareText() function to use everywhere we were using htmlentities.
	** Log :
	** Log : Revision 1.6  1999/10/12 23:14:46  leon
	** Log : Moved localization constants into 'english' module.  Added constant to
	** Log : control whether unregistered shoppers may checkout.
	** Log :
	** Log : Revision 1.5  1999/10/12 00:39:06  chris
	** Log : Moving text into constants in preparation of localization support.
	** Log :
	** Log : Revision 1.4  1999/08/18 22:32:11  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.3  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.
	*/

	function getVariations($attribute)
	{
		global $DatabaseLink;

		print("<UL>\n");

		//show items for this department
		$Query = "SELECT ID, Name ";
		$Query .= "FROM variation ";
		$Query .= "WHERE Attribute = $attribute ";
		$Query .= "ORDER BY DisplayPrecedence, Name ";
		$DatabaseResult = mysql_query($Query, $DatabaseLink);
		while($DatabaseRow = mysql_fetch_row($DatabaseResult))
		{
			$variation_ID = $DatabaseRow[0];
			$variation_Name = $DatabaseRow[1];
		
			print("<LI>");
			print("<A HREF=\"".ScreenURL("edit_variation").
				"&variation=$variation_ID\">");
			print(prepareText($variation_Name));
			print("</A>\n");
		}

		print("<LI>");
		print("<A HREF=\"" . ScreenURL("add_variation") . 
			"&attribute=$attribute\">");
		print("Add Variation");
		print("</A>\n");
		
		print("</UL>\n");
		
	}




	/* Make sure the user has admin rights. */
	if( !$UserInfo["Permission"]["Administrate"] )
	{
		print(L_ADMINATTRIBUTE_DENIED . "<BR>\n");
	}
	else
	{
		print("<A HREF=\"" . ScreenURL("add_attribute") . "\">");
		print(L_ADMINATTRIBUTE_ADDATTRIBUTE);
		print("</A><BR>\n");

		print("<BR>\n");
		print(L_ADMINATTRIBUTE_CHOOSE . "<BR>\n");

		$Query = "SELECT ID, Name ";
		$Query .= "FROM attribute ";
		$Query .= "ORDER BY DisplayPrecedence, Name ";
		$DatabaseResult = mysql_query($Query, $DatabaseLink);
		while($DatabaseRow = mysql_fetch_row($DatabaseResult))
		{
			$attribute_ID = $DatabaseRow[0];
			$attribute_Name = $DatabaseRow[1];

			print("<A HREF=\"" . ScreenURL("edit_attribute").
				"&attribute=$attribute_ID\">");
			print(prepareText($attribute_Name));
			print("</A><BR>\n");

			getVariations($attribute_ID);

		}
	}

?>
