<?php

	/* 
	** File: UPDATE_TAX_RATES
	** Description: This action allows the admin to update the tax rates for 
	**   all of the states.
	** Expected input: Array $Rates, $TaxShipping
	** Version: $Revision: 1.6 $
	** Created: July 13, 1999
	** Author: Shannon -jj Behrens 
	** Email: shannon.behrens@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/12/16 23:58:14 $
	**
	** Log : $Log: UPDATE_TAX_RATES,v $
	** Log : Revision 1.6  1999/12/16 23:58:14  leon
	** Log : Created new function for checking for required global variables.  I've
	** Log : converted a few actions to use this new function.  At some point we should
	** Log : convert them all.
	** Log :
	** Log : Revision 1.5  1999/12/09 23:23:27  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.4  1999/11/15 18:56:22  leon
	** Log : Finished localizing action modules.
	** Log :
	** Log : Revision 1.3  1999/10/14 21:38:14  leon
	** Log : Started pulling text out of action modules
	** Log :
	** Log : Revision 1.2  1999/08/18 22:31:56  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.1  1999/07/28 21:16:43  leon
	** Log : New actions based on code donation from a live project
	** Log :
	**
	** Copyright (c) 1999 Working Dogs.
	*/
	
	/* Make sure the user has admin rights. */
	if( !$UserInfo["Permission"]["Administrate"] )
	{
		print(L_TAXRATES_ACCESS_DENIED . "<BR>\n");
	}
	elseif(! haveGlobals(array("Rates"=>"array", "TaxShipping"=>"array")))
	{
		$ActionResults[] = L_TAXRATES_MISSING_PARAMETER;
	}
	elseif( !is_array($Rates) || !is_array($TaxShipping) )
	{
		$ActionResults[] = L_TAXRATES_NOT_ARRAY;
	}
	else
	{
		for (reset($Rates) ; $state = key($Rates) ; next($Rates))
		{
			$query = "UPDATE tax ";
			$query .= "SET Rate=" . doubleval($Rates[$state]) . ", ";
			$query .= "TaxShipping='" . 
				addslashes(substr($TaxShipping[$state],0,255)) . "' ";
			$query .= "WHERE State='" . 
				addslashes(substr($state,1,2)) . "'";

			/* Execute the query. */
			if ( !mysql_query($query, $DatabaseLink))
			{
				print("<!-- " . mysql_errno() . ":  " . mysql_error() . 
					"   Query was: $query -->\n");
				$ActionResults[] = L_TAXRATES_UNABLE_UPDATE;
				break;
			}
		}


		/* If $ActionResults is still "", then we must have been successful. */
		if ($ActionResults == "")
		{	
			$ActionResults[] = L_TAXRATES_UPDATED;
		}
	}
	
?>
