<?php

	/* 
	** File: UPDATE_ADDRESS
	** Description: Update an address record in the "address" table. 
	** Version: $Revision: 1.6 $
	** Created: June 25, 1999
	** Author: Shannon -jj Behrens
	** Email: shannon.behrens@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/12/09 23:23:23 $
	**
	** Log : $Log: UPDATE_ADDRESS,v $
	** Log : Revision 1.6  1999/12/09 23:23:23  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.5  1999/12/06 21:17:20  leon
	** Log : ECML compliance
	** Log : Overhauled address functions to use ECML form field names.  Ditto with
	** Log : the billing fields on the checkout forms.  Note the change to build.sql.
	** Log : Yes, the address table changed to accomodate new fields.  The billing
	** Log : table changed too.
	** Log :
	** Log : Revision 1.4  1999/11/02 19:09:45  leon
	** Log : Localized the UPDATE action modules
	** Log :
	** Log : Revision 1.3  1999/08/18 22:31:53  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.2  1999/08/10 20:55:10  jj
	** Log : Added code to allow a user to edit his own address informaation. Strict security was inforced so that he can't edit anyone else's.
	** Log :
	** Log : Revision 1.1  1999/07/28 19:41:05  leon
	** Log : Mass update based on code donation from a live project
	** Log :
	**
	** Copyright (c) 1999 Working Dogs.  All rights reserved.
	*/

	// Use the function update an address
	include(APPLICATION_ROOT . "/modules/include/addressFunctions");

	/*
	** Input (most likely from a form action): $addressID, $FirstName, 
	**   $LastName, $Company, $Address1, $Address2, $City, $State, $Country, 
	**   $ZIP, $Email, $Phone1, $Phone2, $Fax.
	** Output: $ActionResults
	*/
	
	
	/* 
	** Deal with security concerns.  Admin's can edit any address record.
	** Mortal users can only edit the address connected to their user profile.
	*/
	if ( !($UserInfo["Permission"]["Administrate"]) AND 
		($addressID != $UserInfo["Address"]["ID"]) )
	{
		$ActionResults[] = L_UPDATEADDRESS_DENIED . 
			"<!-- User trying to edit someone else's address record. -->";
	}
	else
	{
		$inputAddress = getAddressFromEnvironment("input");
	
		//make sure all the info is still good
		if(verifyAddress(array("Name_First","Name_Last"), $inputAddress, &$ErrorDescription))
		{
			//update the record	
			if(updateAddress($addressID, $inputAddress))
			{
				$ActionResults[] = L_UPDATEADDRESS_SUCCESS;
				
				//if we're updating the current user's info
				//then we better refresh it in memory
				if($addressID == $UserInfo["Address"]["ID"])
				{
					$UserInfo["Address"] = $inputAddress;
					$UserInfo["Address"]["ID"] = $addressID;
				}
			}
			else
			{
				$ActionResults[] = L_UPDATEADDRESS_FAILURE;
			}
		}
		else
		{
			$ActionResults[] = $ErrorDescription;
		}
	}
	
?>
