<?php
	/*
	** File: SET_RELATIONSHIPS
	** Description: replaces all the item_item rows for an item
	** Version: $Revision: 1.3 $
	** Created: 9/29/99
	** Author: Leon Atkinson
	** Email: leon@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/12/09 23:23:22 $
	** Log : $Log: SET_RELATIONSHIPS,v $
	** Log : Revision 1.3  1999/12/09 23:23:22  leon
	** Log : Changed ActionResults use so that it's an array instead of a
	** Log : continually-growing string.  Note the little function in standard_library
	** Log : for printing out all the action results.
	** Log :
	** Log : Revision 1.2  1999/11/15 18:56:20  leon
	** Log : Finished localizing action modules.
	** Log :
	** Log : Revision 1.1  1999/09/29 23:06:45  leon
	** Log : Completed Admin side of item to item relationships.
	** Log :
	**
	** Copyright (c) 1999 Working Dogs.  All rights reserved.
	*/


	// Make sure the user has admin rights.
	if(!$UserInfo["Permission"]["Administrate"])
	{
		$ActionResults[] = L_SETRELATIONSHIPS_DENIED;
	}
	else
	{
		//delete all previous rows
		$Query = "DELETE FROM item_item ";
		$Query .= "WHERE Item=$item ";
		$DatabaseResult = mysql_query($Query, $DatabaseLink);
				
		//insert into rows
		$RelationShipsCount = count($input_Relationship);
		$Query = "INSERT INTO item_item VALUES ";
		for($n=0; $n<$RelationShipsCount; $n++)
		{
			list($inputRelatedItem, $inputRelationship) = explode(" ", $input_Relationship[$n]);
			$Query .= "($item, $inputRelatedItem, $inputRelationship),";
		}
		$Query = substr($Query, 0, -1); //trim trailing comma


		$DatabaseResult = mysql_query($Query, $DatabaseLink);
	}


?>