<?php

	/* 
	** File: admin_tax_rates
	** Description: This is a screen that allows the admin to edit the tax
	**   rates for each state.
	** Version: $Revision: 1.9 $
	** Created: July 13, 1999
	** Author: Shannon -jj Behrens 
	** Email: shannon.behrens@clearink.com
	** CVS Author: $Author: leon $
	** Last Revised: $Date: 1999/12/07 21:45:07 $
	** Log : $Log: admin_tax_rates,v $
	** Log : Revision 1.9  1999/12/07 21:45:07  leon
	** Log : All forms should be using StartForm now...
	** Log :
	** Log : Revision 1.8  1999/11/08 22:32:22  leon
	** Log : Added prepareText() function to use everywhere we were using htmlentities.
	** Log :
	** Log : Revision 1.7  1999/11/04 21:35:39  leon
	** Log : Cleaned up the use of paths.  Paths are now all set in index.php3 as
	** Log : constants.  Example settings for Apache/Unix, Apache/Win32, and IIS.
	** Log :
	** Log : Revision 1.6  1999/10/12 23:14:49  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:08  chris
	** Log : Moving text into constants in preparation of localization support.
	** Log :
	** Log : Revision 1.3  1999/09/29 20:55:29  jj
	** Log : admin_tax_rates no longer has its own copy of the states array (rather it uses the one from makeStateSelector).
	** Log :
	** Log : Revision 1.2  1999/08/18 22:32:13  leon
	** Log : Returning opening PHP tag to XML-friendly tag
	** Log :
	** Log : Revision 1.1  1999/07/28 19:41:09  leon
	** Log : Mass update based on code donation from a live project
	** Log :
	**
	** Copyright (c) 1999 Working Dogs
	**
	** We'll output the tax table in one big form with one big table. Hitting
	** the submit button changes all of the tax rates.
	*/
	
	/* Get the list of states to help translate abbreviations. */
	require (APPLICATION_ROOT . "/modules/include/makeStateSelector");

	/* Halt flag. */
	$continueWithReport = TRUE;
	


	/* Make sure the user has admin rights. */
	if( !$UserInfo["Permission"]["Administrate"] )
	{
		print(L_ADMINTAXRATES_DENIED . "<BR>\n");
	}
	else
	{
		/*
		** Get all of the tax records. 
		*/
		$query = "SELECT State, Rate, TaxShipping FROM tax "; 
		/* Execute the query. */
		if ( !($recordSet = mysql_query($query, $DatabaseLink)) )
		{
			print("<!-- " . mysql_errno() . ": " . mysql_error() . 
				"   Query was: $query -->\n");
			$continueWithReport = FALSE;
		}
		else
		{
			if ( !mysql_num_rows($recordSet) )
			{
				print(L_ADMINTAXRATES_TAXTABLEEMPTY . "<BR>\n");
				$continueWithReport = FALSE;
			}
			/* Otherwise, just leave the records in $recordSet. */
		}



		/* 
		** Do the gui.
		*/		
		if ($continueWithReport)
		{
			/* Start the table and the form. */
			print(StartForm("admin_tax_rates", 'post', 'UPDATE_TAX_RATES', FALSE));

			print("<TABLE BORDER=\"1\" WIDTH=\"100%\">\n");
			print("<TR><TD COLSPAN=\"3\">\n");
			print("<B>" . L_ADMINTAXRATES_UPDATETAXRATES . "</B>\n");
			print("</TD></TR>\n");

			/* Output the headings. */
			print("<TR>\n");
			print("<TD ALIGN=\"center\"><B>" . L_ADMINTAXRATES_CODE . "</B></TD>\n");
			print("<TD ALIGN=\"center\"><B>" . L_ADMINTAXRATES_STATE . "</B></TD>\n");
			print("<TD ALIGN=\"center\"><B>" . L_ADMINTAXRATES_RATE . "</B></TD>\n");
			print("<TD ALIGN=\"center\"><B>" . L_ADMINTAXRATES_SHIPPINGISTAXABLE . "</B></TD>\n");

			/* Output each of the records. */
			while ($row = mysql_fetch_row($recordSet))
			{
				/* Parse the row. */ 
				$i = 0;
				$State = $row[$i++];
				$Rate = $row[$i++];
				$TaxShipping = $row[$i++];

				/* Output it. */
				print("<TR>\n");
				print("<TD ALIGN=\"center\">" . prepareText($State) . "</TD>\n");

				print("<TD>" . prepareText($States[$State]) . "</TD>\n");

				print("<TD><INPUT TYPE=\"text\" NAME=\"Rates['$State']\" " . 
					"VALUE=\"$Rate\"></TD>\n");

				print("<TD><SELECT NAME=\"TaxShipping['$State']\">\n");
				if ($TaxShipping == "Y")
				{
					print("<OPTION VALUE=\"Y\" SELECTED>Yes\n");
					print("<OPTION VALUE=\"N\">No\n");
				}
				else
				{
					print("<OPTION VALUE=\"Y\">Yes\n");
					print("<OPTION VALUE=\"N\" SELECTED>No\n");
				}
				print("</SELECT></TD>\n");

				print("</TR>\n");
			}

			/* Finish up the form and the table. */
			print("<TR><TD COLSPAN=\"3\">\n");
			print("<INPUT TYPE=\"submit\" VALUE=\"" . L_ADMINTAXRATES_UPDATE . "\">\n");
			print("<INPUT TYPE=\"reset\" VALUE=\"" . L_ADMINTAXRATES_RESET. "\">\n");
			print("</TD></TR>\n");
			print("</TABLE>\n");
			print("</FORM>\n");
		}
	}

?>
